iphone - 选择 UITableView 中的所有单元格,甚至 iOS 中不可见的单元格

标签 iphone ios uitableview selectall

我有一个方法 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/

相关文章:

ios - UITableView 以编程方式调用滑动操作

ios - UITableViewCell 中的图形故障

iphone - 代码中核心数据简单关系

ios - 在 NSUserDefaults 中设置默认设置。我做错了什么?

ios - 使用 Google SpreadSheet API 更新 iOS Swift 中的特定行

ios - 如何展开和折叠 ScrollView 中的 UIView?

ios - iPhone - 复制字典的可变数组

ios - 影响 UINavigationBar 的后退按钮方法 (iOS)

ios - 敏感数据 : NSString VS NSMutableString (iPhone)

iphone - 复杂的协议(protocol)和代表