willSelectRowAtIndexPath uitableView

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (!self.allowsMultipleSelection) {    // current picker allows no more than one selection
        if (0 < selectedKeys.count) {
            CVFolderListItem* item = [[self.rows objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
            BOOL didContainCurrentSelection = [selectedKeys containsObject:item.key];            

            NSMutableArray* reloadIndexPaths = [NSMutableArray array];
            [self.rows enumerateObjectsUsingBlock:^(NSArray *section, NSUInteger sectionIndex, BOOL *stopSectionLevel) {
                [section enumerateObjectsUsingBlock:^(CVFolderListItem* folderItem, NSUInteger rowIndex, BOOL *stopRowLevel) {
                    if (folderItem.checked) {
                        folderItem.checked = NO;
                        [reloadIndexPaths addObject:[NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex]];
                        *stopSectionLevel = YES;
                        *stopRowLevel = YES;                   
                }];             }];
            [selectedKeys removeAllObjects];
            [tableView reloadRowsAtIndexPaths:reloadIndexPaths withRowAnimation:NO];
            // if the selection has contained before, return nil so as to deselect the cell at the indexPath
            if (didContainCurrentSelection) {
                return nil;
    return indexPath;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s