为什么我不能通过使用NSFetchedResultsController支持的tableview中选择的记录来修改一个字段?

时间:2011-12-03 21:11:46

标签: iphone null nsmanagedobject nslog uistoryboard

(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSError *error=nil;
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
        NSLog(@"Segue");
        [[segue destinationViewController] setDetailItem:selectedObject];
        objet = selectedObject;

        [self showQuizz:selectedObject];
        int num=1;
        [selectedObject   setValue:[NSNumber numberWithInt:num] forKey:@"fldId"];
        if ([self.managedObjectContext save:&error]){
            NSLog(@"fldId Not Saved");
            NSLog(@"Handle the error");
            NSLog(@"Unresolved Error %@, %@",error, [error userInfo]);
        }
}
  1. 最后一个NSLog的打印是:Unresolved Error(null),(null)
  2. 非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

你应该添加一个!,你应该检查保存的结果是否为NO,而不是YES:

if (![self.managedObjectContext save:&error]){
            NSLog(@"fldId Not Saved");
            NSLog(@"Handle the error");
            NSLog(@"Unresolved Error %@, %@",error, [error userInfo]);
        }

换句话说,保存的调用是成功的。您可以看到此here的更多示例。