简体   繁体   中英

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

I have a navigation controller that pushes an 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.

Let's say we have only 2 controllers in the tab bar and every controller will have an UISearchController . Being attached to the navigation item, this search controllers will be configured every time tabBarController(_:didSelect:) is called.

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 .

Have you ever encountered this issue?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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