У меня есть NSMutableArray объектов QuoteMap. Когда я добавляю один из них, используя приведенный ниже код, и перехожу к другому представлению, в котором используются те же данные, при попытке доступа к этому массиву он взрывается с помощью EXC_BAD_ACCESS.
Ниже вы можете видеть, что последний объект в массиве - это "NSObject" вместо "QuoteMap".
Вот где я добавляю цитатуКарта:
- (void)insertQuoteMap:(QuoteMap*)qm {
// THEN TAKE THE QUOTE_MAP_ID, SUBJECT_ID AND QUOTE_ID AND INSERT INTO QUOTE_MAP TABLE
NSInteger quoteMapId = [qm.quote_map_id intValue];
NSInteger subIdInt = [qm.subject_id intValue];
NSInteger quoteIdInt = [qm.quote_id intValue];
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
FMDatabase *database = [FMDatabase databaseWithPath:appDelegate.getDBPath];
if ([database open]) {
[database executeUpdate:@"insert into QUOTE_MAP(quote_map_id, quote_id, subject_id) values(?, ?, ?)",
[NSNumber numberWithInt:quoteMapId], [NSNumber numberWithInt:quoteIdInt], [NSNumber numberWithInt:subIdInt]];
[database close];
}
NSLog(@"QuoteMap inserted the quote_map_id of: %@", qm.quote_map_id);
//Add the object
[appDelegate addQuoteMap:qm];
[qm autorelease];
};
Это то, что вызывает вышеуказанный метод:
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
QuoteMap *qm = [[QuoteMap alloc] init];
NSInteger newQuoteMapId = [appDelegate getNextQuoteMapId];
NSLog(@"quote_map_id= %d subId = %@ quoteId = %@", newQuoteMapId, stringOfSubjectId, selectedQuote.quote_id);
// INSERT INTO QUOTE_MAP TABLE
NSString *stringOfId = [NSString stringWithFormat:@"%d", newQuoteMapId];
qm.quote_map_id = stringOfId;
qm.subject_id = stringOfSubjectId;
qm.quote_id = selectedQuote.quote_id;
//qm.isDirty = YES;
[qm insertQuoteMap:qm];
//Add it to the array.
[qmv.quoteMaps addObject:qm];
[qmv.tableView reloadData];
if (tableAlert.type == SBTableAlertTypeMultipleSelct) {
UITableViewCell *cell = [tableAlert.tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
else
[cell setAccessoryType:UITableViewCellAccessoryNone];
[tableAlert.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
//release
[qm autorelease];