iOS5 - Limit allowsMultipleSelection

560 Views Asked by At

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!

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.indexPathsForSelectedRows.count > 5)
        return nil;
    else
        return indexPath;
}