【发布时间】:2014-10-03 02:53:08
【问题描述】:
我在navigationItem 的titleView 中添加了一个搜索栏,使它看起来像这样。
但是当我点击搜索栏获得焦点时,它会移出屏幕并且键盘会自动关闭,然后看起来像这样。
所以,我无法输入任何内容,也无法看到任何结果。
这是我在 viewDidLoad 方法中将搜索栏添加到导航项的代码。
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0.0, 320.0, 44.0)];
self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
[self.searchBar setShowsCancelButton:NO animated:NO];
searchBarView.autoresizingMask = 0;
self.headSearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.headSearchDisplayController.delegate = self;
self.headSearchDisplayController.searchResultsDelegate = self;
self.headSearchDisplayController.searchResultsDataSource = self;
[searchBarView addSubview:self.searchBar];
self.searchBar.delegate = self;
self.navigationItem.titleView =searchBarView;
我在没有设置自动调整掩码的情况下尝试了它,但没有任何成功。我得到一个提示,这种行为正在发生,因为搜索栏位于 44points 的视图中,该视图再次位于 titleView 内。我猜测 searchResultsTableView 没有足够的高度可以看到,因此我们只能看到覆盖。我该如何解决这个问题?指向正确方向的指针将非常有帮助。
这是情况的动画 gif。
【问题讨论】:
标签: ios uitableview uisearchbar uisearchdisplaycontroller