所以我写了这段代码,在我想选择的行旁边打了一个复选标记,因为我想选择多个行
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
但是当我使用这个方法时:
NSArray *selectedIndexPaths = [self.LightsView indexPathsForSelectedRows];
它只获取我点击的最后一行。复选标记没有选中它吗?
最佳答案
要使 indexPathsForSelectedRows:
方法正常工作,您必须配置 TableView 以允许选择多个单元格:
tableView.allowsMultipleSelection = YES;
关于ios - 如何从 UITableView 中获取选定的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15886493/