gpt4 book ai didi

ios - UISearchBar 范围空白

转载 作者:行者123 更新时间:2023-12-01 19:33:03 25 4
gpt4 key购买 nike

我有 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"];
}

我想在 UISearchBar 时添加 Scopebar当我退出 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

知道如何解决这个问题吗?

最佳答案

当我们为 iOS 13 添加范围栏按钮时,这是适用于我的与 SearchBar 高度相关的解决方案。

  • 实现 - UISearchControllerDelegate 或 UISearchBar Delegate 并分配如下。
    searchController.delegate = self;
    searchController.SearchBar.delegate = self;
  • 覆盖 UISearchControllerDelegate 或覆盖 UISearchBarDelegate 方法。
    -(void) didPresentSearchController:(UISearchController *)searchController {
    [自我resizeTableViewHeaderHeight];
    }
    -(void) didDismissSearchController:(UISearchController *)searchController {
    [自我resizeTableViewHeaderHeight];
    }
    -(void) searchBarCancelButtonClicked:(UISearchBar *)searchBar
    {
    [自我resizeTableViewHeaderHeight];
    }
  • 根据搜索栏高度调整 TableView 标题高度 -
    -(void)resizeTableViewHeaderHeight {
     UIView *headerView = self.table_view.tableHeaderView;
    CGRect frame = headerView.frame;
    frame.size.height = 56; //Make Constant and assign value to it.
    headerView.frame = frame;
    self.table_view.tableHeaderView = headerView;
    }
  • 关于ios - UISearchBar 范围空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61245207/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com