ここで問題が発生しました...
私の BOOL が編集され、最後の NSLog で成功しましたが、ViewController を閉じてから再び入る (テーブルを更新する) と、BOOL は最初の値に戻ります。つまり、[context save:&error] に何か問題があります。関数。何か案は?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
for (int i=0; i<[self tableView:tableView numberOfRowsInSection:0]; i++) {
AccountCell *cell = (AccountCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
[cell setSelected:(i==indexPath.row) animated:NO];
NSManagedObject *user = [arr objectAtIndex:indexPath.row];
[user setValue:[NSNumber numberWithBool:(i==indexPath.row)] forKey:@"active"];
NSLog(@"Index: %i, Active State: %@", i,[user valueForKey:@"active"]);
NSError *error;
if (![context save:&error]) {
NSLog(@"Saving changes to context failed: %@", error);
} else {
// The changes have been persisted.
NSLog(@"Saved data success");
}
}
}