选择UITableView中的所有单元格

问题描述:

当用户按下工具栏中的按钮时,选择表格中的所有单元格(UITableView)的最佳方法是什么?

what would be the best method to select all the cells in the table(UITableView) when the user presses a button in the tool bar?

您可以选择一个单元格调用表视图的selectRowAtIndexPath方法:

You can select a cell calling table view's selectRowAtIndexPath method:

[menuTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];

但是你不能在UITableView中选择多个单元格。
如果要显示和处理单元格的开/关状态,则应使用具有UITableViewCellAccessoryCheckmark类型的附件视图的单元格。 (有关详细信息,请参阅文档)

However you can't select multiple cells in a UITableView. If you want to show and process on/off state of cells you should use cell with accessory view with UITableViewCellAccessoryCheckmark type. (see docs for more details)