Highlight all cells in a specific tableview section
My requirement is that: if the user clicks any row in a section, all the rows in that section need to be highlighted (change background color). I have a custom tableviewcell for this.
I was trying to play with setSelected in the custom tableviewcell, but once you scroll, the cells get reset (obviously).
So, to fix this, in my - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath, I was trying to use [tableView indexPathForSelectedRow].section to retrieve the section, then I was looping through it to select the cells.
The problem ends up being that everytime you scroll, you can kind of notice the cell开发者_C百科s getting selected which makes it look buggy.
Any suggestions?
Make sure that your app isn't relying on the table cells to remember their selection state -- your app should be keeping track of what is and isn't selected somewhere other than in the views.
Your table data source's -tableView:cellForRowAtIndexPath:
method is called each time the table needs to display a new cell, that is, a cell that wasn't visible before. That's your chance to configure the cell properly. It should check the data for the table, determine if the cell is supposed to be selected, and set the selected state appropriately.
精彩评论