【问题标题】:iOS - segmentedControl disappears after using searchBariOS - 使用 searchBar 后,segmentedControl 消失
【发布时间】:2015-11-20 21:34:45
【问题描述】:

通过 Storyboard,我创建了一个 ViewController,上面有一个 UITableView 和一个 SegmentedControl。以编程方式,我添加了一个 SearchController 作为 TableView 的标题。

这是我启动应用程序时发生的情况: 它完美地工作。

但是当我点击搜索栏时,它已经有点乱了。不过,通过隐藏 SegmentedControl 很容易修复。

现在,当我完成搜索时,问题出现了:

SegmentedControl 消失。每当我再次点击搜索栏时,它就会返回,就像在图片 2 中一样,但如果我再次取消,它就会消失。

我已尝试将其从视图中删除并在用户停止搜索后再次添加,但它没有任何改变。这是我的代码:

    searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
searchController.searchResultsUpdater = self;
searchController.dimsBackgroundDuringPresentation = NO;
searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = searchController.searchBar;
searchController.searchBar.scopeButtonTitles = @[];
self.definesPresentationContext = YES;
[searchController.searchBar sizeToFit];

我可以改变什么?

【问题讨论】:

  • 你有没有试过不使用分段控件而只使用 uisearchcontroller 的搜索栏的范围栏?它将消除您遇到的许多布局问题。
  • 太疯狂了,我从来没有想过这个。它可以工作,但不完全......即使用户没有搜索,我怎样才能始终显示范围栏?

标签: ios objective-c uitableview uisegmentedcontrol


【解决方案1】:
searchController.searchBar.showsScopeBar = YES;

【讨论】:

  • 你有没有把它加在这一切的最后:searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; searchController.searchResultsUpdater = 自我; searchController.dimsBackgroundDuringPresentation = NO; searchController.searchBar.delegate = self; self.tableView.tableHeaderView = searchController.searchBar; searchController.searchBar.scopeButtonTitles = @[]; self.definesPresentationContext = YES; [searchController.searchBar sizeToFit];?
  • 是的,这就是问题所在。现在可以了。请更新您的答案以使其更清晰和完整,我会接受!非常感谢。
  • 只有一期。第一次单击搜索栏时,它与范围栏重叠。如果我取消然后再次单击,那就完美了。如何更改 htis?
猜你喜欢
  • 2013-10-03
  • 2017-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-25
  • 2018-11-27
  • 2014-10-18
  • 1970-01-01
相关资源
最近更新 更多