简体   繁体   English

第二个标签栏项中的搜索控制器未显示键盘

[英]Keyboard doesn't show for search controller in second tab bar item

I have a navigation controller that pushes an UITabBarController . 我有一个推送UITabBarController的导航控制器。 So, all my tab view controllers will share the same navigation bar. 因此,我所有的标签视图控制器将共享相同的导航栏。 Not a problem so far because I setup the navigation item's content every time tabBarController(_:didSelect:) is called. 到目前为止,这不是问题,因为每次调用tabBarController(_:didSelect:)时,我都会设置导航项的内容。

Let's say we have only 2 controllers in the tab bar and every controller will have an UISearchController . 假设我们在标签栏中只有2个控制器,并且每个控制器都有一个UISearchController Being attached to the navigation item, this search controllers will be configured every time tabBarController(_:didSelect:) is called. 附加到导航项后,每次调用tabBarController(_:didSelect:)时都会配置此搜索控制器。

Every thing works and looks as required until now. 到现在为止,所有东西都可以正常工作并按要求进行显示。

The problem is that when I tap the search bar from the first controller the keyboard appears and the search works, but when I tap the search bar from the second controller nothing happens. 问题是,当我从第一个控制器点击搜索栏时,键盘会出现并且搜索有效,但是当我从第二个控制器点击搜索栏时,什么也不会发生。

[Being in the second tab] I know that the UISearchBarDelegate 's searchBarShouldBeginEditing(_:) is called, but if I try in that method to set searchController.isActive = true , then the app will crash with the following message: Attempt to present UISearchController on <FirstTabViewController> whose view is not in the window hierarchy . [位于第二个选项卡中]我知道UISearchBarDelegatesearchBarShouldBeginEditing(_:)已被调用,但是如果我尝试使用该方法来设置searchController.isActive = true ,则该应用程序将崩溃并显示以下消息: Attempt to present UISearchController on <FirstTabViewController> whose view is not in the window hierarchy

Have you ever encountered this issue? 您是否遇到过此问题?

当您访问第二个视图控制器时,是否将definesPresentationContext属性设置为true?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM