Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display only one UITableViewCellAccessoryCheckmark at a time
    primarykey
    data
    text
    <p>I'm having a problem with the following code that should allow only one table row to be selected and display a checkmark. Currently there are multiple checkmarks being displayed in the rows.</p> <p>thanks for any help</p> <pre><code>- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //Save the row selected to nsuserdefaults UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; [prefs setObject:cell.textLabel.text forKey:@"countrySaved"]; if (cell.accessoryType == UITableViewCellAccessoryNone) { cell.accessoryType = UITableViewCellAccessoryCheckmark; UIImage *image = [UIImage imageNamed:@"icon-tick.png"]; UIButton *checkmarkBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [checkmarkBtn setImage:image forState:UIControlStateNormal]; [checkmarkBtn setFrame:CGRectMake(0, 0, 19, 19)]; [checkmarkBtn setBackgroundColor:[UIColor clearColor]]; [self.tableView cellForRowAtIndexPath:indexPath].accessoryView = checkmarkBtn; } else { cell.accessoryType = UITableViewCellAccessoryNone; UIButton *checkmarkBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [checkmarkBtn setTitle:@"" forState:UIControlStateNormal]; [checkmarkBtn setFrame:CGRectMake(0, 0, 0, 0)]; [self.tableView cellForRowAtIndexPath:indexPath].accessoryView = checkmarkBtn; } } </code></pre> <p>I saw on some posts that I have to include the following, but I am unsure about how to implement that within the code.</p> <pre><code> cell.accessoryType = UITableViewAccessoryNone; if (indexPath.row == index) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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