Swift addTarget Error on TouchUpInside -


i add button on view , bind event use addtarget , call self.testp , while i'm run , error occured:

2015-06-19 23:08:29.237 ui[16978:1700826] -[ui.viewcontroller testp:]: unrecognized selector sent instance 0x7864d4a0 2015-06-19 23:08:29.240 ui[16978:1700826] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[ui.viewcontroller testp:]: unrecognized selector sent instance 0x7864d4a0' 

the code :

class viewcontroller: uiviewcontroller {  override func viewdidload() {     super.viewdidload()     var btn:uibutton = uibutton.buttonwithtype(uibuttontype.detaildisclosure) as! uibutton     btn.frame = cgrectmake(10, 150, 100, 30)     btn.settitle("button", forstate: uicontrolstate.normal)      //!!!!!!did not work     btn.addtarget(self, action: selector("testp:"), forcontrolevents: uicontrolevents.touchupinside);      self.view.addsubview(btn)      func testp(){         println("tttt")     } } } 

why?!!

just remove : selector , code be:

btn.addtarget(self, action: selector("testp"), forcontrolevents: uicontrolevents.touchupinside) 

and put function outside viewdidload method in viewcontroller class.

you can use "testp:" if function have argument shown below:

func testp(yourargument: string){     println("tttt") } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -