0
我有两个表格,当我检查第一个表格中的项目时,它将添加到第二个表格中,并且此部分工作正常。现在,当我从第一个表中取消选中时,我想从第二个表中删除相同的项目。我正在使用CoreData如何使用NSFetchedResultsController在另一个表中点击同一项目时从一个表中删除项目
谢谢。
我有两个表格,当我检查第一个表格中的项目时,它将添加到第二个表格中,并且此部分工作正常。现在,当我从第一个表中取消选中时,我想从第二个表中删除相同的项目。我正在使用CoreData如何使用NSFetchedResultsController在另一个表中点击同一项目时从一个表中删除项目
谢谢。
如果您使用核心数据,则应从上下文和两个表中删除对象。 确保您实现这些功能在你的表:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath]
atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.tableView endUpdates];
}
我只是想删除第二个表中的数据,它不应该首先从表中删除。 – abhishek 2012-01-04 10:39:02
这不是你问你的问题。请更好地解释你自己,我会尽力帮忙。 – shannoga 2012-01-04 12:33:07