我在故事板上添加UISegmentedControl并在代码中添加SearchBar:
searchController = UISearchController(searchResultsController: nil)
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
searchController.dimsBackgroundDuringPresentation = false
discountTableView.tableHeaderView = searchController.searchBar
激活后搜索栏的位置无效。 如何解决? Before clicking, After clicking
答案 0 :(得分:0)
我通过实现UISearchController
- (void)willPresentSearchController:(UISearchController *)searchController {
if (searchController.searchBar.scopeButtonTitles.count == 0) {
//somewhere I got this
// there is an Apple bug when first time configuring search bar scope buttons
// will be displayed no matter what with minimal searchbar
// to fix this adding scope buttons right before user activates search bar
searchController.searchBar.showsScopeBar = NO;
searchController.searchBar.scopeButtonTitles = @[@"title 1", @"title 2"];
}
}
希望它也能帮到你。