Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In .h file create variable </p> <pre><code>UItableviewCell *selectedCell; </code></pre> <p>In didSelectRow method remove selection from saved cell and save new cell as selected:</p> <pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath if (selectedCell) { selectedCell.accessoryType = UITableViewCellAccessoryNone; } UItableviewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if(cell.accessoryType == UITableViewCellAccessoryCheckmark) { cell.accessoryType = UITableViewCellAccessoryNone; else { cell.accessoryType = UITableViewCellAccessoryCheckmark; } selectedCell = cell; } </code></pre> <p>To prevent problems with reusable cells u can create NSIndexPath variable instead of UITableViewCell in .h file:</p> <pre><code>NSIndexPath *selectedCellIndexPath; </code></pre> <p>and change didSelectRow method:</p> <pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath [tableView scrollToRowAtIndexPath:selectedCellIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO]; UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:selectedCellIndexPath]; selectedCell.accessoryType = UITableViewCellAccessoryNone; UItableviewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if(cell.accessoryType == UITableViewCellAccessoryCheckmark) { cell.accessoryType = UITableViewCellAccessoryNone; else { cell.accessoryType = UITableViewCellAccessoryCheckmark; } selectedCellIndexPath = indexPath; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload