0

Iphone アプリを作成していますが、Core Data の値の 1 つを変更したいと考えています。通常didselect、テーブルビューでインデックスパスメソッドで行を実行しただけです。今、私はテーブル ビューからセルの 1 つに入り、viewController のそのセルのプロパティの 1 つを変更したいと考えています。

これ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 に答える