我有一个静态的UITableView,有很多节。其中一个包含很多细胞,这些细胞将成为选项(点击勾选)。在单个节中循环静态单元格。 UITableView
我有一个NSMutableArray(self.checkedData),它包含所选行的行ID。我无法弄清楚如何循环特定部分中的单元格。它是检查行是否在数组中,如果是的话添加一个复选标记。所以当视图加载时,可以从coredata中拉取选项,然后标记选定的行。
我目前有这个处理添加复选标记。这工作正常。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// determine the selected data from the IndexPath.row
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// determine the data from the IndexPath.row
if (![self.checkedData containsObject:[NSNumber numberWithInt:indexPath.row]])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.checkedData addObject:[NSNumber numberWithInt:indexPath.row]];
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
[self.checkedData removeObject:[NSNumber numberWithInt:indexPath.row]];
}
[tableView reloadData];
}
谢谢。我不太确定如何去做,但这是有道理的。 –
如果此时此刻不可见,则cell可以在ios7上为null。 –
是的,它可以。如果你真的需要访问配置的单元格实例,你可以在表视图的数据源上调用'[tableViewDataSource tableView:tableView cellForRow ...]'方法而不是['tableView cellForRow ...]你非零的单元格的价格(可能无用)初始化/出队/配置单元格 –