这里有问题...
我的 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");
}
}
}