0
在xcode中,我試圖添加一些方法來記錄從tableview中刪除的內容。訪問indexPath.row字段變量
這裏是我的刪除代碼
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObjectContext *context = [self managedObjectContext];
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete object from database
[context deleteObject:[self.contacts objectAtIndex:indexPath.row]];
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
return;
}
NSManagedObject *device = [self.contacts objectAtIndex:indexPath.row];
NSLog(@"Deleting %@ ", [device valueForKey:@"name1"]);
// Remove contact from table view
[self.contacts removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
除了這兩條線
NSManagedObject *device = [self.contacts objectAtIndex:indexPath.row];
NSLog(@"Deleting %@ ", [device valueForKey:@"name1"]);
我試圖訪問在該領域的數據都相當標準的東西它被刪除之前的行,但NSLog返回null。我嘗試了其他變體,並且有一個版本返回了上一行中的變量!
我在這裏錯過了什麼?
感謝道格和保羅之前將這個
。由於某種原因,我認爲刪除發生在幾行較低的位置,但我想只是將其從tableview iteslf中刪除 –