2012-01-11 65 views
0

我正在嘗試刪除核心數據工作的行。我實際上有一個表格視圖,但是當我點擊一行上的刪除按鈕時,它仍然是黑色的,沒有更多的事情發生。刪除核心數據表視圖中的行

下面是我用刪除行的代碼:

- (void) controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath 
{ 
    [[self tableView] deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 

任何想法?

回答

2

可以刪除這樣的行....

- (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]]; 
    } 
} 

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject 
     atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type 
     newIndexPath:(NSIndexPath *)newIndexPath 
{ 
    if (type == NSFetchedResultsChangeDelete) { 
     // Delete row from tableView. 
     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
           withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 
+0

mhhh ......我想你的代碼,但它仍然是相同的。 – thestubborndev 2012-01-12 08:12:01