UITableViewCell复选标记更改select
我正确的认为,要将“打开”的选中标记更改为“closures”,我必须更改“ CellAccessoryType之间的CellAccessoryType和didSelectRowAtIndexPath上的复选checkmark ? 
因为我已经这样做了,但是我注意到这个行为并不像iPhone上自动locking设置上的复选标记单元那样完全相同。
还是有其他方式检查标记是要处理?
- 
在视图控制器中保留一个名为 selectedRow的属性,该属性表示代表表格部分中选中项目的行的索引。
- 
在您的视图控制器的 -tableView:cellForRowAtIndexPath:委托方法中,如果单元格的indexPath.row等于selectedRow值,则将cell的accessoryType设置为UITableViewCellAccessoryCheckmark。 否则,将其设置为UITableViewCellAccessoryNone。
- 
在你的视图控制器的 -tableView:didSelectRowAtIndexPath:委托方法中,将selectedRow值设置为selectedRow的indexPath.row,例如:self.selectedRow = indexPath.row
另一个scheme
 -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSIndexPath *oldIndex = [self.tableView indexPathForSelectedRow]; [self.tableView cellForRowAtIndexPath:oldIndex].accessoryType = UITableViewCellAccessoryNone; [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; return indexPath; } 
是的:你不必检查oldIndex是零:)
[编辑:添加Swift版本]
  override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? { if let oldIndex = tableView.indexPathForSelectedRow { tableView.cellForRowAtIndexPath(oldIndex)?.accessoryType = .None } tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .Checkmark return indexPath } 
Swift 3
 override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { if let oldIndex = tableView.indexPathForSelectedRow { tableView.cellForRow(at: oldIndex)?.accessoryType = .none } tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark return indexPath } 
它应该是
didHighlightRowAtIndexPath
代替
的tableView:didSelectRowAtIndexPath方法
亚历克斯答案只有在添加重新加载表, 在.h
 { int selectedCell; } @property(nonatomic,readwrite)int selectedCell; 
in .m * cellForRowAtIndexPath *
 if(indexPath.row == selectedCell) { cell.accessoryType = UITableViewCellAccessoryCheckmark; cell.selected = YES; } else { cell.accessoryType = UITableViewCellAccessoryNone; cell.selected = NO; } 
并在任何地方didHighlightRowAtIndexPath或didSelectRowAtIndexPath
  self.selectedCell = indexPath.row; [self.tableView reloadData]; 
Zyphrax提出了一个伟大的解决scheme,对我来说非常好! 如果您需要清除之前选定的行,请使用:
 [self.tableView reloadData]; 
在
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
迅速:
 var selectedCell:UITableViewCell?{ willSet{ selectedCell?.accessoryType = .None newValue?.accessoryType = .Checkmark } } 
然后:
 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { selectedCell = self.tableView.cellForRowAtIndexPath(indexPath) self.mapView.selectAnnotation(self.mapView.annotations[indexPath.row], animated: true) } 
如果您想使用您的自定义图像作为accessoryType使用下面的代码
 -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { UIImageView *imgCheckMark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"select_icon.png"]]; [imgCheckMark setFrame:CGRectMake(self.view.frame.size.width - 30, 25, 14, 18)]; imgCheckMark.tag = 1000+indexPath.row; NSIndexPath *oldIndex = [self.tblSelectService indexPathForSelectedRow]; [self.tblSelectService cellForRowAtIndexPath:oldIndex].accessoryView = UITableViewCellAccessoryNone; [self.tblSelectService cellForRowAtIndexPath:indexPath].accessoryView = imgCheckMark; return indexPath; }