I am having trouble understanding how to create a BarButtonItem
and set the sender to AnyObject. I created a BarButtonItem
programmatically and tried to set the sender as any object but the app crashes when the button is pressed.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the 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 a parameter, so it should be:
Plus the method itself will need an
@objc
annotation and I'm pretty sure thatsender
is optional, so: