user4487951
user4487951

Reputation:

Make the accessory type a checkmark for selected cell

I'm trying to make the selected cell (of a custom UITableViewCell) to have a checkmark on it. I tried the following code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CategorieCell *customCell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];

    if (customCell.accessoryType == UITableViewCellAccessoryDisclosureIndicator) {
        customCell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        customCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
}

But when I selected a cell, nothing happened.

Upvotes: 1

Views: 162

Answers (1)

croX
croX

Reputation: 1725

Your mistake is that you dequeue a new custom cell. Instead, you have to find out the cell that actually is selected. Change the first line to:

CategorieCell *customCell = (CategorieCell *)[tableView cellForRowAtIndexPath:indexPath];

This should be it.

Upvotes: 2

Related Questions