I am creating a tableView where I want to limit number of rows selected to 5. If 6th row is selected then a alert will appear stating that I can select only 5 rows. I can check and uncheck the rows but minimum 1 row and maximum 5 rows should be selected. How can I do it. My current code is as follows:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
countId = countId + 1;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
countId--;
}
// countId = [self.tableView indexPathsForSelectedRows].count;
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Where should I set the limit and how to use it? I am able to pass the value of countId between two view controllers I just want to know how I can limit the countId to be between 1 and 5. I am new to this so any help will be appreciated.