我有一个视图行,并且我想第一次通过制表符选择行(或更多行)。这没有问题,但我喜欢在第二次逐行取消选择。一些想法?期待你的到来。致敬Hutch
发布于 2013-12-03 09:58:05
使用以下示例代码进行复选标记选择:https://github.com/vikingosegundo/checkmark/tree/master/Checkmark
设置附件视图需要在tableView:cellForRowAtIndexPath:方法中进行。当您想要从外部更改附件时,外部方法需要首先更改模型,以指示必须在某些单元格中放置复选标记,然后在UITableView上调用reloadData。
存储检查的单元格的一种方法是使用NSIndexSet对象数组-每个部分一个索引集。在下面的示例中,我显示了单个部分的代码,但您应该了解如何使多个部分工作。
// This variable needs to be declared in a place where your data source can get it
NSMutableIndexSet *selected;
// You need to initialize it in the designated initializer, like this:
selected = [[NSMutableIndexSet alloc] init];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if ([selected containsIndex:indexPath.row]) {
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
} else {
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
// Do the rest of your code
return cell;
}
现在,在想要将行设置为选中或取消选中的代码中,只需调用selected addIndex:rowToSelect或selected removeIndex:rowToUnselect,并调用表的reloadData。
https://stackoverflow.com/questions/20347826
复制