我在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'
我做错了什么?
答案 0 :(得分:1)
将代码修改为:
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
实际上没有参数