Reputation: 3665
I know this question has been asked many times. But I can't seem to get past this error. I had it working in a previous version of my app using Objective C.
Both the methods below are within the same UIViewController
.
The view controller is also held as a reference by the root view controller, part of a UINavigationController
.
func loadEditView(sender: AnyObject, animated: Bool = true) {
var editViewController: EditViewController = EditViewController()
// set some stuff up
self.navigationController!.pushViewController(editViewController, animated: animated)
}
override func loadView() {
super.loadView()
var button = UIBarButtonItem(barButtonSystemItem: .Edit, target: self, action: Selector("loadEditView:"))
self.navigationItem.rightBarButtonItem = button
}
The error message is
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyApp.ScaleViewController loadEditView:]: unrecognized selector sent to instance 0x14d643d0'
Upvotes: 2
Views: 1605
Reputation: 318794
You setup your bar button item with the selector loadEditView:
. Not that the name indicates it takes one parameter.
However, your actual loadEditView
function takes two parameters. Hence the error.
You need to change your loadEditView
method to only take one parameter - the sender. There is no way to have the button handler also take the 2nd animated
parameter.
Upvotes: 3