To limit the user to only one choice, which means creating an exclusive list of only one choice, you can follow these steps;
First, you have a global index path specified in your .h file to track an already selected cell ->
NSIndexPath *oldIndexPath;
When you create cells, do not forget to set the accessory type to none, so that no cell is selected by default when viewing the table;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CallIdentifier"]; cell.accessoryType = UITableViewCellAccessoryNone; } return cell; }
Finally, in the didSelectRowAtIndexPath delegate method, add the following code, which will remove the checkmark from the already selected cell and add the checkmark to the newly selected.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (oldIndexPath==nil) {
Hope this works! :)
source share