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
Post a Comment