A structured way to get the result you are looking for:
Subclass UIView for your table cells (containing the button and label). You create these custom views and set them as a contentView for each cell in the table in cellForRowAtIndexPath .
Each of your custom views listens for its own button. When it was pressed, it switches its state and informs the main viewing manager (via the delegate method) that it has been switched. The main view controller calls reloadData in the appropriate cell to cause a reboot with the correct appearance.
Please note that this approach requires that you specify each of the user views that specify the path that it renders in the table - this way it can inform the delegate method of the main view of the controller - this information is necessary to start the reboot of the corresponding cell.
Btw, I suppose you want to see the state of the buttons in the table when the user has finished editing, and your current approach does not very clearly record the state of the state - you will have to iterate over your buttons or add selected items to a mutable array or something like that.
source share