我开始工作(学习)来处理一个UITableView
+核心数据,我开始阅读一些关于它的东西,在我开始编写一个小示例应用程序之后,我可以在其中按下一个按钮,然后数据将显示在tableView
.
我的问题是我已经正确地对其进行了编程,我认为,Xcode 没有向我显示任何警告或错误等。但它不起作用。
谁能告诉我为什么这段代码不起作用?
项目: http ://www.sendspace.com/file/ohc1kn
编辑:如果你不设置:self.fetchedResultsController.delegate = nil;
显示以下错误:
2013-02-17 16:45:05.480 tableView+Coredata[1533:207] *断言失败 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2013-02-17 16:45:05.481 tableView + Coredata [1533:207] CoreData:错误:严重的应用程序错误。在调用 -controllerDidChangeContent: 期间,从 NSFetchedResultsController 的委托中捕获了一个异常。UITableView dataSource 必须从 tableView:cellForRowAtIndexPath: 中返回一个单元格,带有 userInfo (null)
代码用于将 NewObject 插入到数据库和 TableView 中,如果我执行该操作,则会出现上述错误。
// Create a new instance of the entity managed by the fetched results controller.
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
// If appropriate, configure the new managed object.
// Normally you should use accessor methods, but using KVC here avoids the need to add a custom class to the template.
[newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
- (UITableViewCell *)tableView: cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}