【问题标题】:iOS Is there a way to keep the UISearchBar in TableviewHeader when activeiOS有没有办法在活动时将UISearchBar保留在TableviewHeader中
【发布时间】:2015-06-18 15:43:39
【问题描述】:

在我正在创建的当前应用程序中,我想知道是否有办法阻止 UISearchController 搜索栏在其处于活动状态时移动到 UInavigationbar 中。我已将它添加到 tableview tableHeadeView 但我想将它保留在那里而不是在活动时成为 UInvagiationbar。基本上,当搜索处于活动状态时,我想避免隐藏 UInavigationController 导航栏。我怎样才能做到这一点?

我已经尝试将此代码添加到用于更新文本的 searchController 委托方法中,但没有成功:

[self.navigationController setNavigationBarHidden:NO animated:YES];

当前代码:

friendsSearchController = [[UISearchController alloc]initWithSearchResultsController:nil];
friendsSearchController.searchResultsUpdater = self;
friendsSearchController.dimsBackgroundDuringPresentation = NO;
friendsSearchController.searchBar.delegate = self;

friendsSearchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
friendsSearchController.searchBar.placeholder =  @"Find friends";
[friendsSearchController.searchBar sizeToFit];

self.tableView.tableHeaderView = friendsSearchController.searchBar;

【问题讨论】:

  • hidesNavigationBarDuringPresentationUISearchController 属性设置为NO
  • 这行得通,但由于某种原因,searchController 可搜索从其原始位置下降了大约 50 像素,你知道这是为什么以及我该如何解决它吗?
  • 尝试删除一次UISearchBarStyleMinimal,但我不太确定。
  • 我最终在 searchBarShouldBeginEditing 委托方法中重置了框架

标签: ios uitableview uinavigationbar uisearchcontroller


【解决方案1】:

UISearchControllerhidesNavigationBarDuringPresentation 属性决定导航栏在搜索时是否隐藏。设置为NO

friendsSearchController.hidesNavigationBarDuringPresentation = NO;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    相关资源
    最近更新 更多