iphone - 搜索栏从我的根视图控制器中消失

发布于 2024-08-30 07:11:19 字数 706 浏览 9 评论 0原文

我的主屏幕中有一个搜索栏 - 根表视图控制器。如果我浏览其他屏幕并返回,有时搜索栏会消失。这是我的代码。

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野鹿林 2024-09-06 07:11:19

我最近偶然发现了同样的问题,并且能够将其发生范围缩小到仅当搜索栏不在视线范围内(即表格视图已滚动),然后导航离开,然后返回并滚动回到视线范围内。我无法找到有关原因的任何信息,但我可以通过将以下内容放置

来解决此问题: 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文