范围栏在UISearchController中定位
我正在开发一个仅限iPad的应用程序,并且在UIViewController中有一个UITableView。 我设置了一个UISearchController作为UITableView的头部。 这个search控件有三个范围。 我希望范围select器在search栏下方 。 用下面这段代码,我可以在init中得到它,但是当我开始input时,select器向右移动, 并保持在那里 。
这是一个animation:
这里是相关的代码:
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
我从苹果读到一些有趣的东西:
当search栏出现时,范围栏可以出现在附近。 除非在代码中使用search显示控制器(有关这种方式的更多信息,请参阅UISearchDisplayController类参考),否则范围栏将显示在search栏下方,而与方向无关。 当您使用search显示控制器时,当设备处于横向(纵向,位于search栏下方)时,范围栏会显示在search栏右侧的search栏中。
所以对我而言,只使用UISearchBar而不是整个UISearchDisplayController。