我有一個方法selectAll來選擇我的UITableView
中的所有單元格。此方法檢查複選框(UIButton)
。它只適用於"visible"
單元,但不適用於"invisible"
單元!在iOS中選擇UITableView中的所有單元即使不可見單元格
- (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;
}
}
}
}
你不應該對不在屏幕上的單元格做任何事情。 **更改模型**,一旦它們滾動到屏幕上,這些單元格將顯示更改。 – 2013-03-21 09:15:33