Uitableview 聚焦于UISearchBar,但不显示键盘

Uitableview 聚焦于UISearchBar,但不显示键盘,uitableview,uisearchbar,uisearchdisplaycontroller,becomefirstresponder,Uitableview,Uisearchbar,Uisearchdisplaycontroller,Becomefirstresponder,我读过很多关于如何在打开搜索视图时聚焦搜索栏使键盘显示的解决方案,所有这些都是这样的 [searchBar becomeFirstResponder]; mine is [self.searchDisplayController.searchBar becomeFirstResponder]; but I tried both. 现在,我尝试了这个,我还添加了一个 [self.searchDisplayController setActive:YES]; 因为我使用的是SearchDisp

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

[searchBar becomeFirstResponder];
mine is 
[self.searchDisplayController.searchBar becomeFirstResponder];
but I tried both.
现在,我尝试了这个,我还添加了一个

[self.searchDisplayController setActive:YES];
因为我使用的是SearchDisplayController,但到目前为止,我能得到的最好结果是将光标放在搜索栏上,即带覆盖层的uitableview,但仍然没有键盘

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

如果您想查看我的代码: 焦点应该在viewDidLoad方法中执行


再次感谢。

使用UISearchBarDelegate并在头文件中声明搜索栏,如下所示

@interface mySearchScreen : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate> {

UITableView *myTableView;   
NSMutableArray *tableData;
UISearchBar *sBar;//search bar
}

然后在ViewDidDisplay中的搜索栏上使用becomeFirstResponder

- (void)viewDidAppear:(BOOL)animated {
//ensure the keyboard comes up from the start
[sBar becomeFirstResponder];    
[super viewDidAppear:animated];

}

我正在显示textfielddibeginediting:(UITextField*)textField委托方法上的搜索栏

键盘没有显示。所以对于第一个辞职的文本字段作为第一响应者。 i、 e

然后调用具有延迟的方法

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

}

它对序列物质起作用

[self.searchDisplayController setActive:YES animated:YES];
[self.searchDisplayController.searchBar becomeFirstResponder];

如果运气不佳,则检查搜索显示控制器的代理是否链接。也值得检查搜索栏的颜色。

模拟器上,确保单击
切换软件键盘
以使用模拟器的键盘,如图所示


不应该[超级视图显示:动画];首先呼叫[sBar成为第一响应者];适合我,我在
[超级视图显示:动画]
之后调用活动搜索栏,这终于适合我了!投票表决。知道你为什么要这样做吗
[self.searchDisplayController.searchBar becomeFirstResponder]
而不是
[self.searchBar becomeFirstResponder]?这很好,但我建议只需在
viewdide:
方法中执行
[self callSearchBar]
。我们无法可靠地知道控制器转换可能需要多少时间,因此如果延迟太短而无法聚焦
搜索栏
,则可能会产生难看的效果和/或意外的tableview工件+1尽管如此:-)@scottmrogowski您必须使用
self.searchDisplayController.searchBar
,因为您可能已将
UISearchDisplayController
连接到您的
UITableViewController
,因此您的
UITableViewController中没有搜索栏变量“类,但您可以通过
UISearchDisplayController`变量获取此引用。与我面临的问题相同,我的搜索栏处于焦点位置。模拟时光标闪烁,但键盘不显示。你找到解决办法了吗
[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];
[self.searchDisplayController setActive:YES animated:YES];
[self.searchDisplayController.searchBar becomeFirstResponder];