简体   繁体   English

触摸文本区域时,UISearchDisplayController不显示键盘

[英]UISearchDisplayController not displaying keyboard when text area touched

I have a UITableView in a controller that is nested under a UITabBar . 我在嵌套在UITabBar下的控制器中有一个UITableView

The interaction is all wired up in Interface Builder so far, nothing done programmatically in terms of view switching. 到目前为止,所有交互都已在Interface Builder中进行了连接,就视图切换而言,没有以编程方式完成任何操作。

I've added a UISearchDisplayController as the header of my UITableView. 我添加了UISearchDisplayController作为UITableView的标题。 It displays fine, and when I tap on the text entry area, the cancel button appears and the black overlay flies in. 它显示正常,当我点击文本输入区域时,出现“取消”按钮,黑色覆盖层飞入。

However, the keyboard never appears and when tapping the cancel button, the overlay flies out and the cancel button disappears, but the text entry area keeps focus and the caret stays flashing there, so I cannot tap there again to re-display the search results. 但是,键盘永远不会出现,点击取消按钮时,覆盖层会飞出,取消按钮消失,但是文本输入区域会保持焦点,并且插入符号会在那里继续闪烁,因此我无法再次点击那里重新显示搜索结果。

So essentially I have two problems: 所以本质上我有两个问题:

  1. Keyboard not appearing when starting to edit text on UISearchBar from UISearchDisplayController 从UISearchDisplayController开始在UISearchBar上编辑文本时未出现键盘

  2. UISearchBar not loosing focus when cancel button is tapped. 轻按“取消”按钮时,UISearchBar不会失去焦点。

What am I doing wrong? 我究竟做错了什么?

The .xib file that had my tab bar in it contained a UIWindow. 带有我的标签栏的.xib文件包含一个UIWindow。

This lead to all sorts of craziness and in the end I gave up on trying to do this with interface builder, and resorted to constructing the UITabBar in code, thereby not creating a second UIWindow. 这导致了各种各样的疯狂,最后我放弃了尝试使用界面生成器执行此操作,而是诉诸于在代码中构造UITabBar,从而没有创建第二个UIWindow。

This resolved the problems and the UISearchDisplayController behaved correctly. 这样就解决了问题,并且UISearchDisplayController的行为正确。

check this method in UISearchBarDelegate : UISearchBarDelegate检查此方法:

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar;

Try to see if this is getting called and do keyboard-related removal in here. 尝试查看是否被调用,并在此处进行与键盘相关的移除。 If not, try making another UISearchDisplayController . 如果不是,请尝试制作另一个UISearchDisplayController (I actually never use the default viewController's one). (我实际上从来没有使用默认的viewController)。 Also, make sure the delegate is correctly set. 另外,请确保正确设置了委托。

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

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