UISearchBar Область пустого пространства - PullRequest
1 голос
/ 16 апреля 2020

У меня UISearchController в моем приложении:

-(void)setSearchBar {
    self.resultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    [self.resultsController.tableView registerClass:UITableViewCell.self forCellReuseIdentifier:@"SearchTitleCell"];
    self.resultsController.tableView.dataSource = self;
    self.resultsController.tableView.delegate = self;

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.resultsController];
    [self.searchController setSearchResultsUpdater:self];
    [self.searchController setDelegate:self];

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.1")) {
        self.searchController.obscuresBackgroundDuringPresentation = NO;
    }

    self.extendedLayoutIncludesOpaqueBars = YES;

    self.navigationItem.searchController = self.searchController;

    self.searchController.searchBar.delegate = self;

    self.definesPresentationContext = true;
    self.searchController.hidesNavigationBarDuringPresentation = false;

    self.searchController.searchBar.showsScopeBar = NO;
    self.searchController.searchBar.scopeButtonTitles = @[@"One", @"two", @"three"];
}

И я хочу добавить Scopebar при нажатии на полосу UISearchBar и скрыть ее при выходе из UISearchBar, поэтому я использую это код:

- (void)willPresentSearchController:(UISearchController *)searchController {
    self.searchController.searchBar.showsScopeBar = YES;
    [self.searchController.searchBar sizeToFit];
}

- (void)willDismissSearchController:(UISearchController *)searchController {
    self.searchController.searchBar.showsScopeBar = NO;
    [self.searchController.searchBar sizeToFit];
}

Проблема в том, что когда я закрываю UISearchBar (нажав кнопку отмены), я все еще вижу пустое пространство области видимости.

До (Когда нажата панель поиска ): enter image description here

После (После нажатия на панель поиска отменить btn): enter image description here

Любая идея, как это можно исправить проблема

1 Ответ

1 голос
/ 16 апреля 2020

Самым простым тоном может быть добавление

searchController.isActive = false

в вызов willDismiss.

Надеюсь, что это работает

...