I am running into a crazy problem when dealing with the UITableView
, do you have any good sample projects (github) or tutorials that show how to do a multiple selections(checking) on a sectioned UITableView
, i mean a long UITableView
where the user can scroll up and down it and select/deselect the cells in different sections.
The problem i ran is concerning checking cells in different sections, and scrolling up and down the table view. The app crashes, and in a better case, i get random cells checked when i scroll down and up the screen (the table view). So i decided to make a simple project in which i try all that before integrating it into my app.
One of the suit of actions that give rise to the crash is: check cell1 in section1 and check cell2 in section2, then uncheck cell1 in section1. The sample is here, please test it, it s too lightweight, tracking the crash with breakpoint, i found that this method is causing the issue:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *dict = [self.tableData objectAtIndex:[self tableIndexFromIndexPath:indexPath]];//this statement is the issue, i think the app is conflicting between sections when check/uncheck cells
BOOL newState = ![[dict objectForKey:kCellStateKey] boolValue];
NSDictionary *newDict = [NSDictionary dictionaryWithObjectsAndKeys:[dict objectForKey:kCellTextKey], kCellTextKey, [NSNumber numberWithBool:newState], kCellStateKey, nil];
[self.tableData replaceObjectAtIndex:indexPath.row withObject:newDict];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
I really need your expertise to improve my code. Thanx in advance.