Objective c 在UITableview中选择滚动时不工作的多行

Objective c 在UITableview中选择滚动时不工作的多行,objective-c,uitableview,tableview,Objective C,Uitableview,Tableview,我正在执行此代码。当我滚动tableview时,会自动取消选择以前选择的项目 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; } - (void)tableView:

我正在执行此代码。当我滚动tableview时,会自动取消选择以前选择的项目

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}

 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}

UITableViewController
滚动时重复使用行。因此,您必须自己跟踪选定的行。在
UITableViewController

的渲染方法上设置/取消设置选择。您需要保留每个选定行的索引,例如在数组中。然后,在cellForRowAtIndexPath方法下,可以设置与这些选定行索引相关的accessoryType。