ios - When cell is selected, the backgound color of the button will change and then recorver -


i have customize uitableviewcell , there button within it, when set background color of button color other default color(which [uicolor whitecolor]), when cell selected, background color of button change , recover when selection highlight of cell disappear.

how happen , keep button's background color when cell selected?

i recommend inspecting hierarchy of views you've got table view cells. can done: run app on simulator -> click "debug view hierarchy" (see 1st image attached) -> play around inspector (see 2nd image attached). enter image description here

enter image description here

update: after digging while got following (please see 3 screenshots below explaining situation): enter image description here

enter image description here

enter image description here

as can see, there's internal call clears background colors of cell's subviews named _setopaque:forsubview:

having said, if want ensure background color of button remains same should implement selection mechanism of cell in following way:

- (void)setselected:(bool)selected animated:(bool)animated {     [super setselected:selected animated:animated];      // here comes custom color (it's assumed mybutton binded iboutlet     self.mybutton.backgroundcolor = [uicolor greencolor]; // or whatever else } 

it unkind of uikit. hope you.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -