barButtonItem 动作异常

barButtonItem action exception

我在 viewDidLoad 方法中设置 navigationBarItem

var button = UIBarButtonItem(title: "Menu", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("goToMenu:"))
self.navigationItem.rightBarButtonItem = button

我有一个方法可以选择此按钮操作

func goToMenu() {
    var destinationViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("menuBoard") as MenuViewController
    self.navigationController?.presentViewController(destinationViewController, animated: true, completion: nil)
}

但是我遇到了异常

goToMenu:]: unrecognized selector sent to instance 0x15678990'

我做错了什么?

将代码修改为:

func goToMenu(sender: AnyObject) {
    var destinationViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("menuBoard") as MenuViewController
    self.navigationController?.presentViewController(destinationViewController, animated: true, completion: nil)
}

原因是你的Selector("goToMenu:")找的方法只有一个参数,而你的goToMenu实际上没有参数