Q:

How to limit the multi selection in UITableViewController

Here are tableView data source and delegate implementation, and I set the maximum selection is 5.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
    if ([multiOptions count] > 5) {
        [self tableView:tableView didDeselectRowAtIndexPath:indexPath];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selected = NO;
        //show alert
    }
    ...
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
    [multiOptions removeObject:selectedOption];
    ...
}

but here comes a question, if the options exceed the limit, the first click on cell will work just fine. but second time click the cell will call 
didDeselectRowAtIndexPath

again, that's not what i expected, and I tried
[tableView deselectRowAtIndexPath:indexPath animated:YES];

in didSelectRowAtIndexPath, it didn't work, can someone give me a hint, how to correct it? thanks.

A:

You have to check this in tableView:willSelectRowAtIndexPath:
Have a look at the UITableView class reference
especially at the last sentence:

Return Value An index-path object that confirms or alters the selected
  row. Return an NSIndexPath object other than indexPath if you want
  another cell to be selected. Return nil if you don't want the row
  selected.

So something like this will work within tableView:willSelectRowAtIndexPath::
if ([multiOptions count] > 5) return nil;

