我已经使用 IB 向现有的 iPad 应用程序添加了 UIToolBar。然后我用 IB 将它连接到视图控制器并验证连接是否存在。但是,当我单击按钮时,视图控制器中的相应代码并未执行。
我打开了一个空项目并遵循相同的程序,一切都按预期工作。
我很好奇是否对我现有项目中阻止执行 IBAction 代码的不同之处有什么想法?
我正在使用 XCode 4.5.2 和 iOS 6.0(模拟器)进行开发。
任何想法都会受到赞赏,因为我真的很困惑!
As casillic mentioned in the comments, I had this problem due to the UITapGestureRecognizer I was using this to listen for when the user tapped the background so I could dismiss the keyboard if the user is editing a field.
The UITapGestureRecognizer conflicts with the toolbar and causes the code to not be executed when a toolbar item is selected - instead (in my case) it runs the "dismiss keyboard" code I have in my listener for the tab gesture.
To get around this, I added my gesture recogniser to the housing UIScrollView for the text inputs instead of the main containing view.
e.g:
replaced this:
[self.view addGestureRecognizer:tap];
with this:
[scrollView addGestureRecognizer:tap];
(scrollView is hooked up as an IBOutlet for the UIScrollView on my storyboards)