Selected tableViewCell is deselected when holding finger on other cell
I have a tableview with my custom tableViewCell. The issue that I want to fix is that, when a cell is selected, and the user holds his finger on another cell, the currently selected cell is deselected. If the user decides to scroll (not to select the other cell), and raises his finger, the previous cell get it's selection again. I would like the selected cell to remain highlighted as long as the user surely selected another cell.
I've tried t开发者_高级运维o handle this in the tableViewCell's setSelected method, but I cannot differentiate between this case, and the user scrolling - in this case cells are reused (apparently the reused cells receive a setSelected method call).
I've been able to solve it by creating a subclass of the tableView. I have overwritten the touchesBegan, Ended methods where I set a global bool variable called gIsTouching, to YES at began and to NO at ended (important: you have to set this variable before calling [super touchesBegan...] and [super touchesEnded...]).
Then in the custom cell's setSelected method I don't do anything if gIsTouching is YES, otherwise I make the selection.
Hope this helps others with similar issues.
If I am not mistaken , you are looking for the [cell setSelectionStyle:....
settor
精彩评论