我正在制作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;
}
答案 0 :(得分:0)
使用...
创建索引路径NSIndexPath rowIndexPath = [NSIndexPath indexPathWithIndex:1];
然后致电:
NSManagedObject *d = [self.model.frc_Work objectAtIndexPath:rowIndexPath];