我正在开发一个仅限iPad的应用程序,并且在UIViewController中有一个UITableView。我将UISearchController设置为UITableView的标题。此搜索控件具有三个范围。我希望范围选择器位于搜索栏下方。使用下面的代码,我可以在初始化时得到它,但是当我从输入开始时,选择器将移至右侧,并保持在那里。

这是一个动画:

ios - 范围栏在UISearchController中的位置-LMLPHP

这是相关的代码:

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 = false

10-01 16:27
查看更多