2

Me again, I'm loving this library but running into minor issues here and there.

For RaisedButton, what code is needed to create an action when the button is create programatically?

btn1.addTarget(self, action: "okButton", forControlEvents: UIControlEvents.TouchUpInside)

func okButton(sender:RaisedButton!) {
    print("button pressed")
}

results in unrecognized selector sent to instance.

Craig.Pearce
  • 746
  • 7
  • 25

2 Answers2

1

You will need to give "okButton:" as action as it takes an argument.

Try:

btn1.addTarget(self, action: "okButton:", forControlEvents: UIControlEvents.TouchUpInside)
Shripada
  • 6,296
  • 1
  • 30
  • 30
1

In your code remove the unwrapping of the optional parameter:

func okButton(sender: RaisedButton) {
    print("button pressed")
}

Add the ":" at the end of your selector name:

btn1.addTarget(self, action: "okButton:", forControlEvents: .TouchUpInside)

That should solve your issue :)

CosmicMind
  • 1,499
  • 1
  • 10
  • 6