如何在UITableViewCell中添加复选标记

Sah*_*ary 2 xcode cocoa-touch objective-c uitableview

假设我有一个小的tableview(没有滚动),当用户点击一个选项时,它会改变应用程序中的一些设置.我用过这个函数:

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      //some code here
}
Run Code Online (Sandbox Code Playgroud)

现在我想UITableViewCellAccessoryCheckmark用于选择的选项,我的意思是它应该在用户选择的单元格中显示一个复选标记(并从先前选择的选项中删除复选标记).我怎么做?

Pau*_*l.s 8

怎么样

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
  for (UITableViewCell *cell in [tableView visibleCells]) {
    cell.accessoryType = UITableViewCellAccessoryNone;
  }

  UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
Run Code Online (Sandbox Code Playgroud)