tvos - Programatically addTarget action to UIButton -


i tested ton of samples none of them works me. here code:

override func viewdidload() {     super.viewdidload()      let button = uibutton(frame: cgrect(x: 100, y: 100, width: 200, height: 50))     button.backgroundcolor = .green     button.settitle("test button", for: .normal)     button.titlelabel?.sizetofit()     button.addtarget(self, action: #selector(viewcontroller.buttontapped(_:)), for: .touchupinside)      self.view.addsubview(button) }  func buttontapped(_ sender: uibutton) {     print("button tapped.") } 

what missing?

well, following this answer issue .touchupinside. in tvos should .primaryactiontriggered.

button.addtarget(self, action: #selector(viewcontroller.buttontapped(_:)), for: .primaryactiontriggered) 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -