2013-10-28 68 views
0

好吧我最近跟着一個教程來實現一個NSFetchedResultController 它的工作很棒!我還發現了一個關於如何刪除一行的答案。我將建議的代碼行添加到我的實現文件中。使用NSFetchedResultController,刪除按鈕什麼也不做,沒有錯誤,沒有崩潰,沒有行被刪除?

當你向左滑動並按下刪除按鈕時,沒有任何反應。沒有錯誤,沒有行刪除,沒有崩潰。

這裏是我的代碼

// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source 
     [self.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; 

     NSError *error = nil; 
     if (![self.managedObjectContext save:&error]) { 
      // handle error 

     } 
     else if (editingStyle == UITableViewCellEditingStyleInsert) { 
      // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
     } 
    } 
} 

什麼可能我是做錯了什麼?

+0

是'的tableView:commitEditingStyle:'叫,或者是'self.managedObject'零? – bobnoble

+0

我想通了,我有[self.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];它需要是[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];非常感謝您的回覆! –

回答

0

我想通了,我有;

[self.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; 

,它需要的是

[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; Thank you very much for your response!