How to add a checkmark in a UITableViewCell
cocoa-touch, objective-c, uitableview, xcode
Solution
How about
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
for (UITableViewCell *cell in [tableView visibleCells]) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
Problem
Say I have a small tableview(no scroll) and when a user taps an option, it changes some setting in the app. I used this function: ``` - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //some code here } ``` Now I want to use `UITableViewCellAccessoryCheckmark` for the option that is selected, I mean it should display a checkmark in the cell the user selected (and remove checkmark from previously selected option). How do I do that?