Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can do it without UITableView, using just UITapGestureRecognizer :)</p> <p>Also, add <code>NSMutableArray *selectedItems</code> somewhere in your .h file.</p> <pre><code>- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UITableViewCell *cell = (UITableViewCell *)view; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; [cell setBackgroundColor:[UIColor clearColor]]; [cell setBounds: CGRectMake(0, 0, cell.frame.size.width -20 , 44)]; UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleSelection:)]; singleTapGestureRecognizer.numberOfTapsRequired = 1; [cell addGestureRecognizer:singleTapGestureRecognizer]; } if ([selectedItems indexOfObject:[NSNumber numberWithInt:row]] != NSNotFound) { [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; } else { [cell setAccessoryType:UITableViewCellAccessoryNone]; } cell.textLabel.text = [datasource objectAtIndex:row]; cell.tag = row; return cell; } - (void)toggleSelection:(UITapGestureRecognizer *)recognizer { NSNumber *row = [NSNumber numberWithInt:recognizer.view.tag]; NSUInteger index = [selectedItems indexOfObject:row]; if (index != NSNotFound) { [selectedItems removeObjectAtIndex:index]; [(UITableViewCell *)(recognizer.view) setAccessoryType:UITableViewCellAccessoryNone]; } else { [selectedItems addObject:row]; [(UITableViewCell *)(recognizer.view) setAccessoryType:UITableViewCellAccessoryCheckmark]; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload