【问题标题】:iphone - Search bar disappears from my root view controlleriphone - 搜索栏从我的根视图控制器中消失
【发布时间】:2010-04-28 22:05:00
【问题描述】:

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

    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 的怪癖之一?

【问题讨论】:

    标签: iphone search searchdisplaycontroller


    【解决方案1】:

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

    self.tableView.tableHeaderView = searchBar;

    在我的控制器类的 viewWillAppearviewDidAppear 事件中。我假设您发布的代码来自控制器类的 viewDidLoad 方法?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      相关资源
      最近更新 更多