Selector syntax for swift 3.0

I am trying to add a target to a button this way:

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

But this gives me an error:

Using an unresolved identifier 'buttonTapped'

But I declared a function like:

 func buttonTapped(sender: UIButton) { print("All Tapped") } 

Can someone tell me this is the right way to do this in quick 3.

+47
ios iphone swift swift3 uibutton
Aug 29 '16 at 11:49 on
source share
2 answers

Add a goal 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 e.g.

  func buttonTapped(_ sender : UIButton){ .... } 
+68
Aug 29 '16 at 11:51 on
source share

You can do it as follows:

 btnAll.addTarget(self, action: #selector(buttonTapped(sender:)), for: .touchUpInside) 
+15
Aug 29 '16 at 11:51 on
source share



All Articles