Dav*_*ave 13 iphone uisearchbar ios resignfirstresponder
我有一个UISearchBar,点击后会显示键盘.但是,如果用户在显示键盘时按下主页按钮然后返回应用程序,则键盘仍然可见.当应用程序关闭/进入后台时,如何隐藏键盘?
我在viewDidDisappear中尝试了以下内容:
[eventSearchBar resignFirstResponder];
[eventSearchBar endEditing:YES];
Run Code Online (Sandbox Code Playgroud)
我也在appDidEnterBackground中的委托中尝试过这个:
[self.rootController.navigationController.view endEditing:YES];
Run Code Online (Sandbox Code Playgroud)
这些都没有奏效.
Raj*_*071 42
你可以在appDelegate中做到这一点....
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.window endEditing:YES];
}
Run Code Online (Sandbox Code Playgroud)
的Swift版本:
func applicationDidEnterBackground(application: UIApplication) {
window?.endEditing(true)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8165 次 |
| 最近记录: |