ios - Sender: AnyObject crashes when UIBarButtonItem is pressed -


i having trouble understanding how create barbuttonitem , set sender anyobject. created barbuttonitem programmatically , tried set sender object app crashes when button pressed.

import uikit  class viewcontroller: uiviewcontroller {  override func viewdidload() {     super.viewdidload()      // additional setup after loading view.      var toggle = uibarbuttonitem(title: "settings", style: uibarbuttonitemstyle.plain, target: self, action: "togglesidemenu")     self.navigationitem.leftbarbuttonitem = toggle    }  func togglesidemenu(sender: anyobject) {     togglesidemenuview() } 

that "selector" has parameter, should be:

action: "togglesidemenu:"                        ^ 

plus method need @objc annotation , i'm pretty sure sender optional, so:

@objc func togglesidemenu(sender: anyobject?) {     togglesidemenuview() } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -