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

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

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

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -