Button is created in storyboard and I want to add an action.
self.cancel.action = NSSelectorFromString("cancel:")
func cancel(sender: UIBarButtonItem) ->() {
}
This not working. Thanks
Button is created in storyboard and I want to add an action.
self.cancel.action = NSSelectorFromString("cancel:")
func cancel(sender: UIBarButtonItem) ->() {
}
This not working. Thanks
On
Just create a function in your swift class like the following
@IBAction func cancel() {
// your code
}
And connect it in storyboard by ctrl-dragging from the button to your view controller.
On
@IBAction func action() {
// your code
}
var button = UIButton.buttonWithType(UIButtonType.System) as UIButton
button.frame = CGRectMake(100, 100, 100, 50)
button.backgroundColor = UIColor.greenColor()
button.setTitle("Button", forState: UIControlState.Normal)
button.addTarget(self, action: "action", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
See mine.
Adding a UIButton to UIBarbuttonitem.
Initialise a UIBarButtonItem
OR