I am trying to programatically add a UIBarButtonItem to my nav bar (which works), however I cannot get the action to work. What am I doing wrong?
I have the following code under viewDidLoad:
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "visualise"), style: .plain, target: self, action: #selector(visualise(sender:)))
And the following function declared outside the VC class:
func visualise(sender: UIBarButtonItem) {
// stuff to do once the button is tapped
}
I read a few answers saying the function cannot be local but that did not seem to help.
@objcbefore the function, otherwise you get a compiler error that the function is not exposed to Objective-C