聚焦于 UISearchBar 但键盘不出现
我已经阅读了很多关于如何在打开搜索视图时聚焦搜索栏以使键盘出现的解决方案,所有这些都是这样的
[searchBar becomeFirstResponder];
mine is
[self.searchDisplayController.searchBar becomeFirstResponder];
but I tried both.
现在,我尝试了这个,并且我还添加了一个,
[self.searchDisplayController setActive:YES];
因为我正在使用 SearchDisplayController ,但到目前为止,我能得到的最好结果是将光标放在搜索栏上,在其上覆盖有 uitableview ,但仍然没有键盘。
如果我运行模拟器,我可以用电脑键盘在搜索栏上输入内容,但在 iPhone 上我什么也做不了。
如果您想查看我的代码: http://nopaste.info/39fcda4771.html 焦点应该在 viewDidLoad 方法中执行
再次感谢。
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];
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.
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.
If you want to give a look to my code: http://nopaste.info/39fcda4771.html
the focus should be executed in viewDidLoad method
Thanks again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在 textFieldDidBeginEditing:(UITextField *)textField 委托方法上显示搜索栏。
键盘没有显示。因此,首先将 textField 作为第一个响应者。
即
然后延迟调用方法
在哪里
}
它有效
I was showing searchbar on textFieldDidBeginEditing:(UITextField *)textField delegate method.
Keyboard was not showing. So for that first resign textField as firstResponder.
i.e.
Then call method with delay
Where
}
It works
使用 UISearchBarDelegate 并在头文件中声明 searchBar,如下所示...
并在 loadView 中声明您的搜索栏
}
,然后在 viewDidAppear 中的搜索栏上使用 BebeFirstResponder
}
Use the UISearchBarDelegate and declare the searchBar in the header file like this ...
and declare your search bar in loadView
}
and then use becomeFirstResponder on your search bar in viewDidAppear
}
顺序很重要
如果运气不好,请检查搜索显示控制器的委托是否已链接。还值得检查搜索栏的色调颜色。
The sequence matter
If no luck then check if delegate of the search display controller is linked. Also worth checking the tint colour of the search bar.
在
模拟器
上,确保单击切换软件键盘
以使用模拟器的键盘,如图所示。On the
simulator
, make sure that you click onToggle Software Keyboard
to use the keyboard of the simulator as you can see in the image.