Kieran
Kieran

Reputation: 87

UIButton creating error - "unrecognized selector sent to instance"

I have added a button to my view using this code, however it comes up with the error "unrecognized selector sent to instance" and crashes the app.

Does anyone know why this is ?

Many thanks!

       let button: UIButton = UIButton(frame: CGRectMake(100, 400, 100, 50))
        button.backgroundColor = UIColor.clearColor()
        button.setTitle("go Back", forState: UIControlState.Normal)
        button.addTarget(self, action:  "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(button)


    }

    func buttonAction(sender: UIButton!) {

        println("SegueSTGB")
        performSegueWithIdentifier("SegueSTGB", sender: self)

    }

Upvotes: 0

Views: 3994

Answers (1)

s100i29
s100i29

Reputation: 221

You should modify addTarget:

button.addTarget(self, action:Selector("buttonAction:"), forControlEvents: UIControlEvents.TouchUpInside)

Upvotes: 3

Related Questions