我有一个表格列表,用布尔值保存在核心数据中,当我选择一个单元格时,布尔值在核心数据中保存为“是”。但是当我选择一个多于一个单元格时,有 2 个单元格为“是”。我只想将 1 个单元格设置为是。我怎样才能做到这一点。这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BestuhlungCell *cell =(BestuhlungCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.bestuhlungLabel.text = [managedObject valueForKey:@"bestuhlungstitel"];
NSData *data = [[NSData alloc] initWithData:[managedObject valueForKey:@"bestuhlungsfoto"]];
UIImage *image = [UIImage imageWithData:data];
cell.bestuhlungFoto.image = image;
cell.checkButton.hidden=YES;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObjectContext *context = [app managedObjectContext];
// BestuhlungCell *cell = (BestuhlungCell *)[tableView cellForRowAtIndexPath:indexPath];
Bestuhlung *bestuhlung=[self.fetchedResultsController objectAtIndexPath:indexPath];
if ([[bestuhlung valueForKey:@"check"] boolValue]) {
[bestuhlung setValue:[NSNumber numberWithBool:NO] forKey:@"check"];
} else {
[bestuhlung setValue:[NSNumber numberWithBool:YES] forKey:@"check"];
}
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
[self.navigationController popViewControllerAnimated:YES];
}