UITableViewCell checkmarks
- by burki
Hi! When you select a cell in the UITableView, the
- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath
is called. There some of the NSManagedObjects will be updated with the right values and the row will be deselected.
Well, it works all right, but you can't see any selection of the tableviewcell. I found out that the access on core data causes the problem, that means, if i comment out the lines with the commands of updating the NSManagedObjects, it all works like I want, with a smooth selection and deselection.
Can anybody help? Thanks.
- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//[table deselectRowAtIndexPath:indexPath animated:YES];
NSMutableSet *favoriteGroups = [NSMutableSet setWithSet:element.favoriteGroup];
NSMutableSet *elements = [NSMutableSet setWithSet:[(FavoriteGroup *)[fetchedResultsController objectAtIndexPath:indexPath] element]];
UITableViewCell *checkedCell = [table cellForRowAtIndexPath:indexPath];
if (checkedCell.accessoryType == UITableViewCellAccessoryCheckmark) {
[elements removeObject:element];
[favoriteGroups removeObject:[fetchedResultsController objectAtIndexPath:indexPath]];
[[table cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
} else {
[elements addObject:element];
[favoriteGroups addObject:[fetchedResultsController objectAtIndexPath:indexPath]];
[[table cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
}
element.favoriteGroup = favoriteGroups;
FavoriteGroup *favoriteGroup = [self.fetchedResultsController objectAtIndexPath:indexPath];
favoriteGroup.element = elements;
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}