iphone - 搜索栏从我的根视图控制器中消失
我的主屏幕中有一个搜索栏 - 根表视图控制器。如果我浏览其他屏幕并返回,有时搜索栏会消失。这是我的代码。
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44.0)];
searchBar.delegate = self;
searchBar.tintColor = [UIColor blackColor];
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;
searchDisplayController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
我的代码有什么问题吗?或者这是 SDK 3.0 的怪癖之一?
I have a search bar in my main screen - root table view controller. If I browse other screens and come back, sometimes, the search bar disappears. Here's my code.
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44.0)];
searchBar.delegate = self;
searchBar.tintColor = [UIColor blackColor];
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;
searchDisplayController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
Is there anything wrong with my code or is it one of the quirks of SDK 3.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近偶然发现了同样的问题,并且能够将其发生范围缩小到仅当搜索栏不在视线范围内(即表格视图已滚动),然后导航离开,然后返回并滚动回到视线范围内。我无法找到有关原因的任何信息,但我可以通过将以下内容放置
来解决此问题:
self.tableView.tableHeaderView = searchBar;
在 viewWillAppear 中 > 或我的控制器类的 viewDidAppear 事件。我假设您发布的代码来自控制器类的 viewDidLoad 方法?
I stumbled across this same issue recently and was able to narrow it's occurrence down to only when the search bar is out of sight (i.e. the table view has been scrolled), then navigated away from, then return to and scrolled back into sight. I have been unable to find any information on what the cause is, but I was able to workaround it by placing this:
self.tableView.tableHeaderView = searchBar;
in either the viewWillAppear or viewDidAppear event of my controller class. I'm assuming the code you've posted is from the viewDidLoad method of your controller class?