Lapinou Lapinou - 1 year ago 209
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;


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download