【问题标题】:Scope buttons hiding behind the UITableview隐藏在 UITableview 后面的范围按钮
【发布时间】:2018-05-11 22:27:39
【问题描述】:

我正在使用 UISearchController 创建一个搜索屏幕,我必须在其中显示三个范围按钮。我以编程方式放置了搜索栏。但不知何故,范围按钮隐藏在 UITableView 后面。

- (void)viewDidLoad {
    [super viewDidLoad];
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.searchBar.delegate = self;
    self.tblFoundList.tableHeaderView = self.searchController.searchBar;
    self.definesPresentationContext = YES;
    [[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setDefaultTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}];
    [[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setAttributedPlaceholder:[[NSAttributedString alloc] initWithString:@"Search by" attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor]}]];
    self.searchController.searchBar.tintColor = [UIColor purpleColor];
    self.searchController.searchBar.barTintColor = [UIColor groupTableViewBackgroundColor];
    self.searchController.searchBar.scopeButtonTitles = @[@"A",@"B", @"C"];
    [self.searchController.searchBar sizeToFit];
}

有人可以帮忙吗?谢谢。

【问题讨论】:

  • 你在使用自动布局吗?
  • @iPeter 我以编程方式放置,没有自动布局。
  • 那么请检查你的tableviewbuttons的框架。根据屏幕截图,您的tableviewy position 似乎不正确。
  • 尝试给出 tableHeaderView 的高度,你在哪个操作系统中检查这个? iOS11 提供了可能导致此问题的默认标题高度。更改表头高度应该可以工作。
  • @iPeter,我尝试更改我创建的 TableView 的 y 位置,但它没有显示任何结果。不过谢谢你的帮助

标签: ios uitableview uisearchcontroller iphone-8-plus


【解决方案1】:

正如我之前提到的,我以编程方式创建了 UISearchController,所以图像中的 UITableview 是 UISearchController 的 UITableview,这就是为什么没有任何影响。

所以我得到了帮助

UISearchController Search Bar Position Drops 64 points

UISearchBar presented by UISearchController in table header view animates too far when active

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
    {
      if (bar == self.searchController.searchBar) {
        return UIBarPositionTopAttached;
      }
      else { // Handle other cases
        return UIBarPositionAny;
      }
    }

在添加以下方法时,搜索栏向上移动并且范围按钮可见。

但感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-03
    • 2017-03-31
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    相关资源
    最近更新 更多