2017-10-18 24 views
0

我有類似的問題,像這裏: SearchBar in NavigationBar IOS 11 在我的情況下,我沒有在TableView頂部的工具欄。當顯示視圖時不應該顯示searchBar - ios 11

我在VC補充搜索欄:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    UISearchController * search = [[UISearchController alloc] initWithSearchResultsController:nil]; 
    search.searchResultsUpdater = self; 
    self.navigationItem.searchController = search; 
    self.navigationItem.hidesSearchBarWhenScrolling = YES; 

    self.navigationController.navigationBar.prefersLargeTitles = NO; 
    self.navigationController.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever; 
} 

現在搜索欄始終可見。它應該是默認隱藏的。 SearchBar應該顯示,當我拉下tableView。

我在做什麼錯?

回答

0

的問題是,我添加圖片背景:

UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"somethingImage"]]; 
[background setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
[self.view addSubview:background]; 
[self.view sendSubviewToBack:background]; 

然後搜索控制器有一些問題。我不知道如何修復它。我認爲這是一個蘋果錯誤。