我有一个方法 selectAll 来选择 UITableView
中的所有单元格。此方法检查复选框(UIButton)
。它仅适用于“可见”
单元格,但不适用于“不可见”
单元格!
这是我的方法:
- (IBAction)selectAll:(id)sender {
for (NSInteger s = 0; s < self.tableView.numberOfSections; s++) {
for (NSInteger r = 0; r < [self.tableView numberOfRowsInSection:s]; r++) {
CustomCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:s]];
if(!cell.checkbox.selected){
cell.checkbox.selected = !cell.checkbox.selected;
cell.account.checked = cell.checkbox.selected;
}
}
}
}
最佳答案
来自文档:
cellForRowAtIndexPath:
返回值:
An object representing a cell of the table or
nil if the cell is not visible
or indexPath is out of range.
您可以创建一个包含选中或未选中的 bool 值列表的数组,并在单元格可见时询问它。
关于iphone - 选择 UITableView 中的所有单元格,甚至 iOS 中不可见的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15543324/