Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Navigation Bar item not calling action

I have an item on the navigation bar that calls an action. It stopped working. I have disconnected the item from the action and re-attached. Still no action. The action is attached in the storyboard. How do I debug or solve this issue?

like image 801
lascoff Avatar asked Aug 20 '16 22:08

lascoff


2 Answers

Try something like this

If you have a parameter

 override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "ButtonName", style: .done, target: self, action: #selector(YourViewController.yourAction(_:)))

}

Without parameter

 override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "ButtonName", style: .done, target: self, action: #selector(YourViewController.yourAction))

}
like image 142
Mannopson Avatar answered Nov 08 '22 13:11

Mannopson


If you used the drag and drop functionality for creating the IBAction method, make sure it created the method for the button and not the "Bar Button Item."

The easiest way to check is by opening the Document Outline view in your Storyboard.

like image 41
Roman Sheydvasser Avatar answered Nov 08 '22 15:11

Roman Sheydvasser