我开始工作(学习)处理UITableView
+核心数据,我开始阅读一些内容,在开始编写一个示例应用程序之后,我可以按一下按钮,然后那么数据将显示在tableView
中。UITableView +核心数据
我的问题是,我编程正确,我认为,Xcode不显示任何警告或错误等,但它不起作用。
有人可以告诉我为什么这段代码不起作用吗?
项目: http://www.sendspace.com/file/ohc1kn
编辑: 如果你不设置:显示self.fetchedResultsController.delegate = nil;
以下错误:
2013-02-17 16:45:05.480 tableView+Coredata[1533:207] * Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2013-02-17 16:45:05.481 tableView+Coredata[1533:207] CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath: with 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;
}
我不愿意下载一个随机的zip文件。请将您的代码作为文本发布。 – sjwarner 2013-02-17 15:18:19
请编辑您的问题来描述什么不起作用。这是一个错误吗?数据在错误的单元格?究竟是什么问题(每个问题有一个问题)?请明确点。并将你的问题附近的代码添加到你的问题中。 – 2013-02-17 15:35:00
现在请修复代码缩进。 – vikingosegundo 2013-02-17 15:59:34