我遇到了非常不寻常的问题。我用fetchviewcontroller实现了coredata。当我删除最后一节的特定行时,我收到了错误。
CoreData:错误:严重的应用程序错误。在调用-controllerDidChangeContent:期间,从NSFetchedResultsController的委托中捕获到异常。 *** - [__ NSArrayM insertObject:atIndex:]:对象不能为userInfo为空(null)
然后我的桌子完全被打扰了,所有排都弄乱了......请看截图。 经过长时间的调试,我发现魔法发生在 viewForHeaderInSection 中。如果我将文本分配给标签然后出现此问题,如果我不这样做它并且永远不会有任何问题。请参考以下代码。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *programId = [[[_fetchedResultsController sections] objectAtIndex:section] name];
ImageQueue *info = [_fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];
UIView *baseView = [[UIView alloc] init];
baseView.backgroundColor = [UIColor appOrangeColor];
UILabel *lblProgramTitle = [[UILabel alloc] init];
lblProgramTitle.frame = CGRectMake(0, 0, 0, 0);
lblProgramTitle.numberOfLines = 0;
lblProgramTitle.lineBreakMode = NSLineBreakByWordWrapping;
lblProgramTitle.backgroundColor = [UIColor clearColor];
lblProgramTitle.textColor = [UIColor blackColor];
lblProgramTitle.font = [UIFont fontWithName:FONT_OPENSAN_SEMIBOLD size:16];
//This line when commented work otherwise issue occure.
lblProgramTitle.text = [NSString stringWithFormat:@"%@\n( %@ )",info.eventName,info.programName];
lblProgramTitle.tag = 100;
[baseView addSubview:lblProgramTitle];
NSLog(@"%@\n( %@ )",info.eventName,info.programName);
[lblProgramTitle enableAutolayout];
[lblProgramTitle leadingMargin:5];
[lblProgramTitle trailingMargin:100];
[lblProgramTitle topMargin:15];
[lblProgramTitle bottomMargin:15];
UIButton *btnUploadAll = [UIButton buttonWithType:UIButtonTypeSystem];
btnUploadAll.backgroundColor = [UIColor clearColor];
btnUploadAll.frame = CGRectMake(0, 0, 0, 0);
[btnUploadAll setTitle:@"Upload All" forState:UIControlStateNormal];
[btnUploadAll setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btnUploadAll.titleLabel.font = [UIFont fontWithName:FONT_OPENSAN_SEMIBOLD size:16];
[btnUploadAll addTarget:self action:@selector(uploadAll:) forControlEvents:UIControlEventTouchUpInside];
[baseView addSubview:btnUploadAll];
btnUploadAll.tag = [programId integerValue];
[btnUploadAll enableAutolayout];
[btnUploadAll fixWidth:80];
[btnUploadAll fixHeight:50];
[btnUploadAll trailingMargin:5];
[btnUploadAll centerY];
return baseView;
}
执行endupdate时会出现上述错误
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
// The fetch controller has sent all current change notifications, so tell the table view to process all updates.
[tableCart endUpdates];
}