Mike Schmidt Mike Schmidt - 1 year ago 36
iOS Question

Iterating through Table View Cells?

I know that there are many questions out there like this, but I have tried their solutions and have not gotten anything to work, so please hear me out.

I have a view controller called

, and a table view cell type called
. I am using a switch that, when on, I want a label of the cell to be displayed. I know how to setup the switch, the function, and how to toggle the label. The only part I don't understand is looping through all the cells.

I have tried: in the main "tableview" function, adding each cell to an array (for some reason they do not stay in the array), and looping through each of the MainTableView.visibleCells(), but nothing seems to work. Any suggestions?


You don't need to iterate anything. Simply reload the table view when the switch changes. Then make sure the implementation of cellForRowAtIndexPath sets up each cell appropriately for the current state of the switch.