0

I need to limit the number of multiple selection in a Table View, but I don't have any idea for where can I begin.

Thanks and regards!

chemitaxis
  • 13,889
  • 17
  • 74
  • 125

2 Answers2

3
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.indexPathsForSelectedRows.count > 5)
        return nil;
    else
        return indexPath;
}
beeshar
  • 31
  • 2
1

Create a NSMutableArray. Whenever someone selects a cell, check the number of items already in the array. If it's less than your limit, put a reference to that cell's backing data into your array. If it has reached its limit, either ignore the selection or replace a previous selection...whichever makes sense for your app.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57