Ios 搜索栏和分段控件

Ios 搜索栏和分段控件,ios,swift,xcode,swift3,Ios,Swift,Xcode,Swift3,我在故事板上添加了UISegmentedControl,并在代码中添加了搜索栏: searchController = UISearchController(searchResultsController: nil) searchController.searchBar.delegate = self searchController.searchBar.sizeToFit() searchController.dimsBackgroundDuringPresentation = false d

我在故事板上添加了UISegmentedControl,并在代码中添加了搜索栏:

searchController = UISearchController(searchResultsController: nil)
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
searchController.dimsBackgroundDuringPresentation = false
discountTableView.tableHeaderView = searchController.searchBar
搜索栏激活后的位置无效。 如何修复它? ,

我通过实现
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"];
    }

}

希望它也能帮助您。

您设置了约束吗?@AhmadF是的。在条下分段控制。约束:顶部、左侧、右侧和高度。以及分段控制下的TableView顶部、底部、左侧、右侧。我找到了解决此问题的方法。需要设置searchBarStyle=.minimal。也许还有别的办法?我不能用ScopeBar。我需要始终显示分段控制。