【发布时间】:2010-08-22 17:56:45
【问题描述】:
我支持删除包含 tableView 的 UIView 中的行:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.fetchedResultsController.managedObjectContext
deleteObject:[self.fetchedResultsController
objectAtIndexPath:indexPath]];
NSError *error;
if (![[self.fetchedResultsController managedObjectContext] save:&error]) {
NSLog(@"Unresolved error %@, %@, %@", error, [error userInfo],
[error localizedDescription]);
}
else {NSLog(@"Apparently successful");}
[self.tableView reloadData];
}
}
当我尝试此操作时,我在控制台中收到“显然成功”消息,但随后在 configureCell 中收到 SIGABRT。就好像某处对象没有被删除,而 configureCell 正试图呈现一个丢失的对象。 (但是,当我重新运行该应用程序时,记录就消失了。)
有什么想法吗?
【问题讨论】:
-
发布更多代码会对我们有所帮助,尤其是您的 tableView:cellForRowAtIndexPath: 方法,这可能是这里的罪魁祸首。
-
好的,这是崩溃前发生的事情: - (UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { [...不适合的样板文件此评论...] [self configureCell:cell atIndexPath:indexPath];返回单元格; } - (void)configureCell:(UITableViewCell)cell atIndexPath:(NSIndexPath*)indexPath { NSManagedObject *mo = [fetchedResultsController objectAtIndexPath:indexPath]; int objtype = [[(Type *)[mo valueForKey:@"type"] globalid] intValue];然后——砰!
标签: ios iphone uitableview core-data