15

所以我写了这段代码来在我想要选择的行旁边打一个复选标记,因为我想要多个选择的行

UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];

if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    cell.accessoryType = UITableViewCellAccessoryNone;
} else {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}

但是当我使用该方法时:

NSArray *selectedIndexPaths = [self.LightsView indexPathsForSelectedRows];

它只获取我点击的最后一行。复选标记没有选择它吗?

4

1 回答 1

23

为了使该indexPathsForSelectedRows:方法正常工作,您必须配置表格视图以允许选择多个单元格:

tableView.allowsMultipleSelection = YES;
于 2013-04-08T18:53:07.120 回答