I have a table displaying items. Each cell has a button that is used to display something else about the item. In order to track what is being displayed (used in the parent view as the table is in a modal), I set the button to be selected.
My issue is that I want to ensure only ONE button is “selected” at a time. So if user taps button A, then later taps button B, how can I “deselect” button A?
Again, the buttons are embedded in each cell, so how can I iterate through each cell and disable the buttons (WITHOUT reloading the table data)?
I guess you save the information about wether a button is pressed or not out of the button. You have to do so, because the cells can be reused, and so if you only save this info in the selected property of a button, it will be lost if the cell is being reused.
Taking into account that you have the index of the selected button cell saved somewhere, you can iterate through all the visible cells in the UITableView using visibleCells
method. For each UITableViewCell, you disable the button if its index is not the one you want. Use indexPathForCell: to check the index.
And you should be good. Of course, everytime the dataSource asks for a cell, check if the indexPath is the selected and if so, set the button.selected to YES.