我需要對下列問題的一些提醒:刪除對象NSFetchedResultsController
我使用的是iOS主從應用程序模板爲我的應用程序,我遇到問題時,我從主原因請看詳細信息頁面。 我的問題是爲什麼NSFetchedResultsChangeDelete
在繼續時被觸發?
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
UITableView *tableView = self.tableView;
List *list = nil;
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
但在我的情況,我想,當用戶通過從右我還從服務器中刪除對象刷卡表格單元格中刪除對象做到以下幾點,即,這個效果很好,當有一個表視圖並沒有segueing 。如果我阻止NSFetchResutlsController
表單刪除對象,當我繼續細節如下,然後從細節回來後查看錶視圖單元格不響應我的點擊事件。即表格不會延續,點擊時沒有任何反應,
任何人都可以引導這裏出了什麼問題嗎?我應該如何正確實現這個功能?
case NSFetchedResultsChangeDelete:
list = (List*)anObject;
BOOL visible = [self.navigationController.topViewController isKindOfClass:[RKGMasterViewController class]];
if(list.listSyncStatus == [NSNumber numberWithInt:1] && visible)
{
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self deleteDataFromServer:list];
}
好的,當用戶滑動表格單元格時觸發表格視圖的事件? – Umair
當用戶滑動表格視圖時,會出現一個刪除按鈕。沒有其他的。如果用戶點擊刪除按鈕,那麼它將在tableViewDelegate中運行一個名爲'tableView:commitEditingStyle:forRowAtIndexPath:'的函數。在這裏,您應該刪除核心數據實體並向服務器發送調用以刪除相同的對象。 – Fogmeister
好吧,我已經完成了你所說的話,我的一半問題已經解決。現在剩下的問題是,當我點擊單元格塞格細節視圖,並返回到主視圖後,該項目不存在,因爲NSFetchResults控制器的didChangeObject方法 [tableView deleteRowsAtIndexPaths:@ [indexPath] withRowAnimation:UITableViewRowAnimationFade]; 行在執行時執行,我該如何解決這個問題? – Umair