Lapinou Lapinou - 6 months ago 105
iOS Question

Select all cells in UITableView even invisible cell in iOS

I have a method selectAll to select all my cells in my

. This method check a checkbox
. It's work very well just for the
cells but not for the

Here my method:

- (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]];

cell.checkbox.selected = !cell.checkbox.selected;
cell.account.checked = cell.checkbox.selected;



From the documentation:


Return Value:

An object representing a cell of the table or nil if the cell is not visible or indexPath is out of range.

You can create an array that contains a list of booleans for checked or unchecked, and interrogate it when the cell is visible.