Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector syntax for swift 3.0 [duplicate]

I am trying to add target into button this way:

btnAll.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)

But it is giving me an error:

Use of unresolved identifier 'buttonTapped'

But I declared function like:

func buttonTapped(sender: UIButton) {

    print("All Tapped")
}

Can anybody tell me what is the correct way to do this in swift 3.

like image 542
Ram Mani Avatar asked Aug 29 '16 11:08

Ram Mani


2 Answers

Add target like,

should now be written as #selector(buttonTapped(sender:)) or use #selector(buttonTapped(_:))

btnAll.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)

then change your function like,

@objc func buttonTapped(_ sender : UIButton){

 ....
 }
like image 58
Anbu.Karthik Avatar answered Nov 07 '22 03:11

Anbu.Karthik


You can do it this way:

btnAll.addTarget(self, action: #selector(buttonTapped(sender:)), for: .touchUpInside)
like image 29
Dharmesh Kheni Avatar answered Nov 07 '22 05:11

Dharmesh Kheni