在弹出窗口的选项卡栏中的导航控制器中取消 UITableView 搜索后,UINavigationBar 无响应
好吧,这是一个奇怪的问题,我可以轻松地用一个新项目重现它。
设置如下:
我有一个 UISplitViewController。在左侧我有一个 UITabBarController。在此选项卡栏控制器中,我有两个 UINavigationController。在导航控制器中,我有 UITableViewControllers。这些表格视图上有搜索栏。
好的,此设置会发生的情况是,如果我处于纵向模式并在弹出窗口中调出此视图,然后我在其中一个表格视图中开始搜索并取消它,导航栏将变得无响应。也就是说,“后退”按钮以及右侧按钮都无法点击。
如果我在横向模式下执行完全相同的操作,这样我们就不会处于弹出窗口中,这种情况就不会发生。导航栏保持响应。
因此,问题似乎只发生在弹出窗口内。
我还注意到,如果我进行搜索但单击搜索结果中的某个项目,最终会将某些内容加载到拆分视图的“详细信息视图”中并关闭弹出窗口,然后返回到弹出窗口,然后单击搜索的取消按钮,导航栏是响应式的。
我的应用程序是一个通用应用程序,在 iPhone 界面中使用相同的选项卡栏控制器,并且它可以正常运行而不会出现此问题。
正如我上面提到的,我可以轻松地用一个新项目重现这一点。如果您想自己尝试一下,请执行以下步骤:
启动新项目 - 拆分视图
创建新的 UITableViewController 类(我命名为 TableViewController)
取消注释 viewDidLoad 方法以及 viewDidLoad 中的 rightBarButtonItem 行(这样我们将在导航栏中有一个“编辑”按钮)
输入您想要从 numberOfSectioinsInTableView 和 numberOfRowsInSection 方法返回的任何值
打开 MainWindow.xib 并执行以下操作:
请注意,您需要在中间的“查看模式”下查看 xib,以便可以展开项目的内容
将选项卡栏控制器拖到 xib 中以替换导航控制器项
将导航控制器拖到 xib 中,作为选项卡栏控制器下的另一个项目
删除选项卡栏控制器下的其他两个视图控制器(因此,现在我们的选项卡栏上只有一个导航控制器)
在导航控制器内,拖入一个表视图控制器并用它来替换视图控制器(根视图控制器)
将新的表视图控制器的类更改为上面创建的类(对我来说是TableViewController)
双击新表视图控制器下的表视图将其打开(将显示在拆分视图控制器内的选项卡栏中)
将“搜索栏和搜索显示”拖到表格视图上
保存 xib
在模拟器中运行项目
在纵向模式下,单击“根列表”按钮可弹出弹出窗口
注意“编辑”按钮是可点击的
点击搜索框 - 我们进入搜索模式
单击“取消”按钮退出搜索模式
请注意“编辑”按钮不再起作用
所以,任何人都可以帮我弄清楚为什么会发生这种情况?
谢谢,
马克
Ok, this is an odd one and I can reproduce it with a new project easily.
Here is the setup:
I have a UISplitViewController. In the left side I have a UITabBarController. In this tab bar controller I have two UINavigationControllers. In the navigation controllers I have UITableViewControllers. These table views have search bars on them.
Ok, what happens with this setup is that if I'm in portrait mode and bring up this view in the popover and I start a search in one of the table views and cancel it, the navigation bar becomes unresponsive. That is, the "back" button as well as the right side button cannot be clicked.
If I do the exact same thing in landscape mode so we are not in a popover, this doesn't happen. The navigation bar stays responsive.
So, the problem only seems to happen inside a popover.
I've also noticed that if I do the search but click on an item in the search results which ends up loading something into the "detail view" of the split view and dismissing the popover, and then come back to the popover and then click the Cancel button for the search, the navigation bar is responsive.
My application is a universal app and uses the same tab bar controller in the iPhone interface and it works there without this issue.
As I mentioned above, I can easily reproduce this with a new project. Here are the steps if you want to try it out yourself:
start new project - split view
create new UITableViewController class (i named TableViewController)
uncomment out the viewDidLoad method as well as the rightBarButtonItem line in viewDidLoad (so we will have an Edit button in the navigation bar)
enter any values you want to return from numberOfSectioinsInTableView and numberOfRowsInSection methods
open MainWindow.xib and do the following:
please note that you will need to be viewing the xib in the middle "view mode" so you can expand the contents of the items
drag a Tab Bar Controller into the xib to replace the Navigation Controller item
drag a Navigation Controller into the xib as another item under the Tab Bar Controller
delete the other two view controllers that are under the Tab Bar Controller (so, now our tab bar has just the one navigation controller on it)
inside the navigation controller, drag in a Table View Controller and use it to replace the View Controller (Root View Controller)
change the class of the new Table View Controller to the class created above (TableViewController for me)
double-click on the Table View under the new Table View Controller to open it up (will be displayed in the tab bar inside the split view controller)
drag a "Search Bar and Search Display" onto the table view
save the xib
run the project in simulator
while in portrait mode, click on the Root List button to bring up popover
notice the Edit button is clickable
click in the Search box - we go into search mode
click the Cancel button to exit search mode
notice the Edit button no longer works
So, can anyone help me figure out why this is happening?
Thanks,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,已从 Apple 开发者技术支持处得到答复。他们对此进行了调查,发现这是 UIPopoverController 中的一个错误。他给了我一个可行的解决方法,但在取消搜索后,导航栏中的右侧按钮最终会滑过屏幕。但是,至少它解决了这个问题。他还建议我向 Apple 发送错误报告,我也这样做了。希望他们能在下一版本的 SDK 中解决这个问题。
以下是苹果工程师回复的相关部分的副本:
Ok, got an answer from Apple Developer Technical Support. They investigated it and found it is a bug in the UIPopoverController. He gave me a workaround that kind of works but the right button in the nav bar ends up sliding across the screen after canceling the search. But, at least it fixes the issue. He also suggested I send in a bug report to Apple and I've done that as well. Hopefully they will fix this in the next version of the SDK.
Here's a copy of the relevant portion of the Apple engineer's response:
我尝试了提到的 rightBarItem 技术,但它对我不起作用。我必须这样做(这实际上也是一种黑客行为)
这可能是因为我的 UINavigationBar 不是与弹出窗口统一的,但我不能肯定地说。
I tried the rightBarItem technique mentioned, but it didn't work for me. I had to do this (which is also a hack really)
This might be because my UINavigationBar isn't one unified with the popover, but I can't say for sure.