Selected UIButton disappears inside selected UITableViewCell

前端 未结 5 1803
一个人的身影
一个人的身影 2021-01-06 00:39

I have a table, I have cellForRowAtIndexPath delegate for it and I have instance of UITableViewCell being created inside that method, which I return. Somewhere in cellForRow

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-06 01:20

    Hey, I know this is an old post but this can be helpful : UITableView will try to propagate its selection state in the whole hierarchy of its subviews. If one subview responds to -setHighlighted: it will be updated according to the cell selection state.

    That explains why the button becomes blue (highlighted), but also why the button image disappears sometimes : a UIButton contains UIImageView instances to display its images and will swap the image of each image view according to its state (-[UIControl state]). But the table view cell comes and sets the highlighted flag of the button's image view to YES (which the button did not foresee), but this image view has no image for its highlighted state, so you see nothing, even if the button keeps swapping images according to its state.

    The solution I used was, whenever the cell is selected or highlighted, I set the highlighted flag of the button's image view to NO.

提交回复
热议问题