UISearchBar在navigationBar

时间:2015-12-14 20:58:24

标签: ios objective-c uitableview uisearchcontroller

我有两个视图控制器,每个视图控制器包含UISearchControllerUITableViewviewDidLoad中的代码是:

SearchResultsTableViewController *searchResultController = [[SearchResultsTableViewController alloc]initWithNibName:@"SearchResultsTableViewController" bundle:nil];
UINavigationController *navSearchResultsController = [[UINavigationController alloc] initWithRootViewController:searchResultController];

self.searchController = [[UISearchController alloc] initWithSearchResultsController:navSearchResultsController];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = YES;
[self.searchController.searchBar sizeToFit];
self.searchController.searchBar.delegate = self;
self.searchController.delegate = self;

self.tableView.tableHeaderView = self.searchController.searchBar;
self.tableView.userInteractionEnabled = YES;

第一个视图控制器是rootViewController,它完美无缺地运行。第二个视图控制器是根据段选择通过导航控制器推送的。

[self.navigationController pushViewController:self.vc];

第二个视图控制器只有一个问题。当我点击searchBar时,它会动画到顶部并进入导航栏下方,而第一个动画在其位置动画并且不会上升。

谁能告诉我如何禁用此动画? 我希望在搜索时将searchBar保持在同一位置。它与两个视图控制器的实现完全相同。为什么每个人都采取不同的行动?

谢谢,

1 个答案:

答案 0 :(得分:0)

hidesNavigationBarDuringPresentation boolean on the UISearchController设置为NO

self.searchController.hidesNavigationBarDuringPresentation = NO;

或尝试this answer,听起来与您尝试的相似。但你可能想调整这一行:

[super setActive: visible animated: animated]; // instead of passing animated, pass NO
相关问题