0

我正在制作一个 Iphone 应用程序,我想更改 Core Data 中的一个值。通常我只didselect在表格视图中完成索引路径方法的行。现在我来自一个表格视图并进入其中一个单元格,并希望在 viewController 中更改该单元格中的一个属性。

这样做:NSManagedObject *d = [self.model.frc_Work objectAtIndex:1];会给我一个错误。

//The way I have done it before

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
          NSManagedObject *d = [self.model.frc_Work objectAtIndexPath:indexPath];
          [d setValue:[NSNumber numberWithInt:1] forKey:@"status"];
}


//How do I do it this way 
- (IBAction)btnDone:(id)sender {

    NSManagedObject *d = [self.model.frc_Work objectAtIndex:1];

    [d setValue:self.tvTheNote.text forKey:@"notes"];

    [self.model saveChanges];

    self.tvTheNote.text = @"";

    [self dismissModalViewControllerAnimated:YES];
}

我的 Frc 代码是:

 - (NSFetchedResultsController *)frc_Work

{

// If the frc is already configured, simply return it

if (_frc_Work) return _frc_Work;



// Otherwise, create a new frc, and set it as the property (and return it below)

_frc_Work = [_cdStack frcWithEntityNamed:@"Work" withPredicateFormat:nil predicateObject:nil sortDescriptors:@"title,YES" andSectionNameKeyPath:nil];



return _frc_Work;

}
4

1 回答 1

0

使用...创建索引路径

NSIndexPath rowIndexPath = [NSIndexPath indexPathWithIndex:1];

然后调用:

NSManagedObject *d = [self.model.frc_Work objectAtIndexPath:rowIndexPath];
于 2012-12-01T21:09:46.677 回答