iphone - 搜索栏从我的根视图控制器中消失
问题描述:
我的主屏幕中有一个搜索栏 - 根表视图控制器。如果我浏览其他屏幕并返回,有时搜索栏会消失。这是我的代码。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的怪癖之一?
答
我最近偶然发现了同样的问题,只能在搜索栏不在视线范围内(即表视图已滚动),然后导航离开,然后返回并向后滚动进入视线。在任我控制器类的viewWillAppear中或viewDidAppear事件
self.tableView.tableHeaderView = searchBar;
:我一直无法找到病因是什么的任何信息,但我可以通过将该要解决它。我假设你发布的代码来自你的控制器类的viewDidLoad方法?