ios - 当我打开搜索栏时,导航栏隐藏了

标签 ios objective-c uinavigationbar uisearchcontroller

我的 导航栏 中嵌入了一个 UISearchController,当我单击它时,整个导航栏会离开屏幕,直到我按下屏幕上的另一个区域,然后它回来了。这是 a link到视频。 (视频可能已经上传,请稍等片刻,链接有效)

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.dimsBackgroundDuringPresentation = NO;
    // Use the current view controller to update the search results.
    self.searchController.searchResultsUpdater = self;
    //Setting Style
    self.searchController.searchBar.barStyle = UIBarStyleBlack;
    self.searchController.searchBar.barTintColor = [UIColor colorWithRed:49.0/255.0 green:49.0/255.0 blue:61.0/255.0 alpha:1.0];
    self.searchController.searchBar.backgroundImage = [UIImage imageNamed:@"BG"];
    self.searchController.searchBar.placeholder = @"Search Artists, Songs, Albums etc.";
    self.searchController.searchBar.keyboardAppearance = UIKeyboardAppearanceDark;
    [self.searchController.searchBar sizeToFit];
    self.definesPresentationContext = YES;
    self.searchController.searchBar.tintColor = self.view.window.tintColor;
    [self.searchController.searchBar setTintColor:[UIColor colorWithRed:(226.0/255.0) green:(56.0/255.0) blue:(83.0/255.0) alpha:(1.0)]];
    self.searchController.searchBar.delegate = self;
    self.navigationItem.titleView = self.searchController.searchBar;
}

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController{
    NSString *searchString = searchController.searchBar.text;
    NSLog(@"You searched for %@", searchString);
    [searchResultsTableView reloadData];
 }

-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    [self.view addSubview:searchResultsTableView];
}

最佳答案

需要添加以下内容

self.searchController.hidesNavigationBarDuringPresentation = NO;

停止 UISearchController 在激活时隐藏导航栏(ref docs link)。

关于ios - 当我打开搜索栏时,导航栏隐藏了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34024056/

相关文章:

objective-c - 这是什么意思? "Writable atomic property ' fileManager' 无法将合成的 setter/getter 与用户定义的 setter/getter 配对”

ios - 使用NSArray时,避免“越界”的最佳方法是什么?

iphone - 使用 MonoTouch 将自定义后退按钮添加到导航栏

ios - 在 NavBar Swipe Hide 上,HeaderCell 创建了一个透明的间隙并且内容通过

ios - 对于我需要在 plist 中的哪个位置设置 bundle id 感到困惑

ios - 圆形 mask View 动画太快,不可点击

ios - 为 Alamofire 全局设置超时间隔

ios - 当新条目出现时,如何从右到左为标签内的文本设置动画?

ios - 我的导航栏出现在故事​​板中,但未出现在模拟器中

ios - 如何从网络服务加载数组?