UISearchController 中范围栏的定位
Positioning of scope bar in UISearchController
我正在开发一个 iPad-only 应用程序,我在 UIViewController 中有一个 UITableView。我设置了一个 UISearchController 作为 UITableView 的 header。此搜索控件具有三个范围。我希望范围选择器位于搜索栏 下方 。使用以下代码,我可以在初始化时获取它,但是当我从输入开始时,选择器向右移动, 并保持在那里。
这是一个动画:
这里是相关代码:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = @[@"Uno",@"Dos", @"Tres"];
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.showsScopeBar = YES;
self.definesPresentationContext = YES;
[self.searchController.searchBar sizeToFit];
提前致谢
我还在我的应用程序中加入了 UISearchController。我正在使用 Xcode 7.1。
我遇到了同样的问题,只是从我的代码中删除了 "self.searchController.searchBar.showsScopeBar"。
将值更改为 false 或将其完全删除。
self.searchController.searchBar.showsScopeBar = 假
这是我从苹果读到的一些有趣的东西:
When a search bar is present, a scope bar can appear near it. The
scope bar displays below the search bar, regardless of orientation,
unless you use a search display controller in your code (for more
information on the way this works, see UISearchDisplayController Class
Reference). When you use a search display controller, the scope bar is
displayed within the search bar to the right of the search field when
the device is in landscape orientation (in portrait orientation, it’s
below the search bar).
所以对我有用的是只使用 UISearchBar 而不是整个 UISearchDisplayController。
我正在开发一个 iPad-only 应用程序,我在 UIViewController 中有一个 UITableView。我设置了一个 UISearchController 作为 UITableView 的 header。此搜索控件具有三个范围。我希望范围选择器位于搜索栏 下方 。使用以下代码,我可以在初始化时获取它,但是当我从输入开始时,选择器向右移动, 并保持在那里。
这是一个动画:
这里是相关代码:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = @[@"Uno",@"Dos", @"Tres"];
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.showsScopeBar = YES;
self.definesPresentationContext = YES;
[self.searchController.searchBar sizeToFit];
提前致谢
我还在我的应用程序中加入了 UISearchController。我正在使用 Xcode 7.1。
我遇到了同样的问题,只是从我的代码中删除了 "self.searchController.searchBar.showsScopeBar"。
将值更改为 false 或将其完全删除。
self.searchController.searchBar.showsScopeBar = 假
这是我从苹果读到的一些有趣的东西:
When a search bar is present, a scope bar can appear near it. The scope bar displays below the search bar, regardless of orientation, unless you use a search display controller in your code (for more information on the way this works, see UISearchDisplayController Class Reference). When you use a search display controller, the scope bar is displayed within the search bar to the right of the search field when the device is in landscape orientation (in portrait orientation, it’s below the search bar).
所以对我有用的是只使用 UISearchBar 而不是整个 UISearchDisplayController。