专注于 UISearchBar 但键盘没有出现 [英] Focus on the UISearchBar but the keyboard not appear

查看:24
本文介绍了专注于 UISearchBar 但键盘没有出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于如何在打开搜索视图时聚焦搜索栏以显示键盘的解决方案,所有这些都是这样的

I've read so many solution on how can i focus a searchbar to make keyboard appear when i open my search view, and all of that are like this

[searchBar becomeFirstResponder];
mine is 
[self.searchDisplayController.searchBar becomeFirstResponder];
but I tried both.

现在,我尝试了这个,我还添加了一个

Now, I tried this, and I also added a

[self.searchDisplayController setActive:YES];

因为我使用的是 SearchDisplayController,但到目前为止我能得到的最好结果是将光标放在搜索栏上,uitableview 上有一个覆盖层,但仍然没有键盘.

because I'm using a SearchDisplayController, but so far the best result i can have is to have the cursor on the searchbar, the uitableview with an overlay on it, but still no keyboard.

如果我运行模拟器,我可以用电脑键盘在搜索栏上输入,但在 iPhone 上我什么也做不了.

If I run the simulator I can type on the searchbar with my computer's keyboard, but on an iPhone I can't do anything.

如果你想看看我的代码:http://nopaste.info/39fcda4771.html焦点应该在 viewDidLoad 方法中执行

If you want to give a look to my code: http://nopaste.info/39fcda4771.html the focus should be executed in viewDidLoad method

再次感谢.

推荐答案

我在 textFieldDidBeginEditing:(UITextField *)textField 委托方法上显示搜索栏.

I was showing searchbar on textFieldDidBeginEditing:(UITextField *)textField delegate method.

键盘未显示.因此,对于第一次将 textField 辞职为 firstResponder.即

Keyboard was not showing. So for that first resign textField as firstResponder. i.e.

[textField resignFirstResponder];

然后延迟调用方法

[self performSelector:@selector(callSearchBar) withObject:NULL afterDelay:0.2];

哪里

-(void)callSearchBar{
[self.searchDisplayController setActive: YES animated: YES]; 
self.searchDisplayController.searchBar.hidden = NO;
[self.searchDisplayController.searchBar becomeFirstResponder];

}

有效

这篇关于专注于 UISearchBar 但键盘没有出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆