UISearchBar not showing keyboard when tapped

2019-04-20 04:19发布

I programmatically added a UISearchBar in the view, did some initial setup. However, when I tap the search bar, the keyboard is not showing up. I looked up some question on this site, and none seems working for me.

Here is the code snippets I used to setup the search bar

self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(origin.x,origin.y,width,height)];
self.searchBar.searchBarStyle = UISearchBarStyleDefault;
self.searchBar.translucent = YES;
self.searchBar.barTintColor = [UIColor whiteColor];
...
[self.searchBar setDelegate:self];
[self.view addSubView:self.searchBar];

Any suggestions on fix this? Thanks!

1条回答
时光不老,我们不散
2楼-- · 2019-04-20 04:57

If you're using Xcode 6.0.1, its possible that your hardware keyboard is taking over for the simulator keyboard. When running the simulator, make sure this option is unchecked. This should trigger the simulator keyboard when you tap in your Search Bar:

enter image description here]

Also, this post explains how to get back to the behavior of the keyboard in Xcode 5.1.1:

In Xcode 6, how do I use the hardware keyboard but display the software keyboard in the iOS simulator

查看更多
登录 后发表回答