在视图控制器 IOS 中更新核心数据中的属性



我正在制作一个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;
}

使用...

NSIndexPath rowIndexPath = [NSIndexPath indexPathWithIndex:1];

然后致电:

NSManagedObject *d = [self.model.frc_Work objectAtIndexPath:rowIndexPath];

最新更新