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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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))
}
回答2:
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.