我有一个页面 Controller ,我在其中添加了两个 TableView 。在添加的每个 TableView 搜索 Controller 标题中,viewForHeader 方法也返回“最近”和“其他” View 。
我的问题是点击搜索栏后搜索栏没有出现。 它似乎向上移动,我看不到我在那里输入的内容。 搜索栏可能隐藏在“连接”、“消息”选项卡后面。
当键盘成为第一响应者时,如何使搜索栏保持在同一位置? 任何帮助将不胜感激。
最佳答案
你是否在 ViewDidLoad
中使用了以下代码行
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
[self.view bringSubviewToFront:searchBarRef]; // add this line where ever u need..!
-(void)loadSearchBar {
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
self.tableView.tableHeaderView = searchBar;
}
在 ViewDidLoad
调用此 loadSearchBar
方法。
这会将搜索栏添加到 TableView
。
关于ios - 搜索栏不会出现在 ios 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34312614/