Please re-read the answer I wrote here to your previous, similar question, which explains one solution to your problem.
Again, you should consider keeping an array of on/off settings. You can use NSMutableArray
or a C array of int
or BOOL
values, whatever you want. But it definitely sounds like you need a data model.
Your -tableView:cellForRowAtIndexPath:
looks up values of this array. Each value in the array corresponds in some way to a row in the table.
If you only have one section, then you can simply use the i
th element of the array to set the checked state of the i
th row of the table view. If you use NSMutableArray
to store NSNumber
s, you can handle resizing quite easily.
If you have more than one section, keep an array of arrays. Each top-level array corresponds to a section. Each inner array corresponds to a section's rows.
If you use NSMutableArray
to store NSMutableArray
s of NSNumber
s, you can handle resizing and section addition and deletion quite easily.
The method -tableView:cellForRowAtIndexPath:
then sets up cells with or without checkmarks, depending on the array's value.
Having a data model gives you the freedom to programmatically perform "select all" and "deselect all" button operations.
For example, when you click a button to "select all" cells:
Loop through the array and set each value to YES
or 1
or whatever "on" label you chose originally.
Call [tableView reloadData]
, which is a method that goes back to -tableView:cellForRowAtIndexPath:
and which will set a cell's checkmark state based on the state of values in the updated array.