ios - About addTarget for a button inside a UITableViewCell -


i'm not able understand why addtarget in uibutton not working in specific case.

so, there uitableviewcell create button programmatically, like:

let myclickbutton : uibutton = {     let button = uibutton()     button.settitle("hit test", for: .normal)     button.tintcolor = uicolor.white     button.addtarget(self, action: #selector(printmessage), for: .touchupinside)     button.isuserinteractionenabled = true     return button }() 

and, there function in uitableviewcell class button supposed calling:

func printmessage(){     print("button clicked") } 

however, printmessage function never called , there no error in console. me understand problem on case? seems problem of being in uitableviewcell tested on regular viewcontroller , worked fine.

thanks ton!

depending on closure button is, try setting target after uitableviewcell has been instantiated. other that, i'm not sure problem without seeing more code.


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -