I am trying to fix the EXC_BAD_ACCESS error that occurs when accessing the NSMutableDictionary in tableView: cellForRowAtIndexPath: indexPath. Now it works when I populate ridesDict with the loadHistoryFromDBExtended method as follows:
self.ridesDict = [self loadHistoryFromDBExtended];
NSLog(@"rides dict %@", self.ridesDict);
However, I do not want to call [self loadHistoryFromDBExtended] for each load cell, since the dictionary will not change, so I tried to move:
self.ridesDict = [self loadHistoryFromDBExtended];
to view DidLoad, and now I get an EXC_BAD_ACCESS error when using:
NSLog(@"rides dict %@", self.ridesDict);
in the table View: cellForRowAtIndexPath: indexPath. From what I read, it seems that I have problems with saving / releasing memory, but I cannot figure it out. I tried [self.ridesDict save] in viewDidLoad after calling the loadHistoryFromDBExtended method, but that didn't help. I am very new to this, so I would appreciate any directions as to where to go.
Edit: Here is the loadHistoryFromDBExtended method:
-(NSMutableDictionary *)loadHistoryFromDBExtended
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
FMDatabase* db = [FMDatabase databaseWithPath:[self getDBPath]];
if (![db open])
{
NSLog(@"Could not open db.");
[pool release];
}
FMResultSet *rs = [db executeQuery:@"SELECT * FROM R order by date desc"];
NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] init];
while ([rs next])
{
NSMutableArray *usersDictArray = [NSMutableArray array];
[usersDictArray addObject:[rs stringForColumn:@"rNames"]];
[usersDictArray addObject:[rs stringForColumn:@"dName"]];
[usersDictArray addObject:[rs stringForColumn:@"date"]];
[myDictionary setObject:usersDictArray forKey:[rs stringForColumn:@"rID"]];
[usersDictArray release];
}
return myDictionary;
[myDictionary release];
[pool drain];
}
source
share