AJS AJS - 1 year ago 110
iOS Question

Ambiguous use of 'dismiss()' on UIButton when converting to swift 3.0

I have programmatically created an UIButton in swift 2.0 named

, which signifies the dismissal of an
. When the user clicks the button, the view controller containing the button dismisses. When I converted to swift 3.0 I kept getting this error:

  • Ambiguous use of 'dismiss()'

I tried adding arguments to
but it didn't work. Here is my original code without the arguments.

noBtn.addTarget(self, action: #selector(SetUpNameViewController.dismiss), for: UIControlEvents.touchUpInside)

Answer Source

Rewrite like this. First, give the same class a dismiss method:

func dismiss() {

Second, change your selector to #selector(dismiss).

Now your selector will call your dismiss function which will call dismiss(animated:completion:) which is what you are trying to do.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download