UISearchController:searchBar和scopeBar在第一次触摸事件时重叠 [英] UISearchController: searchBar and scopeBar overlap on first touch event
问题描述
我正在尝试使用Apple的最新UISearchController实现一个简单的搜索栏。但是,如果我使用搜索栏的范围栏来获取过滤器选项,我似乎无法正常工作。
I'm trying to implement a simple search bar using Apple's latest UISearchController. However I can't seem to get it to work correctly if I use the search bar's scope bar to get a filter choice.
范围栏始终显示我可以使用
The scope bar always shows which I could live with
但是在第一次触摸事件中搜索栏和示波器条重叠。
but on the very first touch event the search bar and scope bar overlap.
我使用了Apple的TableView示例代码应用程序,但它没有改变任何内容。
I used Apple's TableView sample code app but it didn't change anything.
- (void)viewDidLoad {
[super viewDidLoad];
_resultsTableController = [[APLResultsTableController alloc] init];
_searchController = [[UISearchController alloc] initWithSearchResultsController:self.resultsTableController];
self.searchController.searchResultsUpdater = self;
[self.searchController.searchBar sizeToFit];
self.searchController.searchBar.showsScopeBar = YES;
[self.searchController.searchBar setScopeButtonTitles:@[@"First",@"Second"]];
self.tableView.tableHeaderView = self.searchController.searchBar;
// we want to be the delegate for our filtered table so didSelectRowAtIndexPath is called for both tables
self.resultsTableController.tableView.delegate = self;
self.searchController.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = NO; // default is YES
self.searchController.searchBar.delegate = self; // so we can monitor text changes + others
// Search is now just presenting a view controller. As such, normal view controller
// presentation semantics apply. Namely that presentation will walk up the view controller
// hierarchy until it finds the root view controller or one that defines a presentation context.
//
self.definesPresentationContext = YES; // know where you want UISearchController to be displayed
}
我也实现了搜索栏的委托方法,但它只是切换了重叠的时间。
I implemented the search bar's delegate methods as well but it just switches the timing of the overlap.
是否有人能够使用iOS 8s UISearchController并使用searchBar的范围栏实现搜索栏?
提前致谢
推荐答案
我花了三天时间研究同一个问题我可以找到的帖子,最后在Apple Dev论坛上找到了解决方案,所以我想发布一个更新来帮助遇到这个问题的下一个人。
I just spent three days working on this same issue going through all of the posts I could find and just finally found the solution on the Apple Dev forum so thought I would post an update to help the next person that encounters this issue.
分辨率是确保属于UISearchController的搜索栏上的showsScopeBar属性设置为false,即Swift中的 UISearchController.searchBar.showsScopeBar = false
。
The resolution is to make sure that the showsScopeBar property on the search bar belonging to a UISearchController is set to false, i.e. UISearchController.searchBar.showsScopeBar = false
in Swift.
问题似乎是Apple的设计意图是将 showsScopeBar
属性用于独立搜索栏而不是由UISearchController控制的搜索栏。不幸的是,在课程文档中没有提到这一点。在我看来,设计决定不好,但它就是它。
The issue seems to be that Apple's design intent is for the showsScopeBar
property to be used with standalone search bars not search bars controlled by a UISearchController. Unfortunately this is not called out in the class documentation. Bad design decision in my opinion but it is what it is.
讨论在以下主题 https://devforums.apple.com/thread/235803 (截至2018-01-26的死链接)。
The discussion is in the following thread https://devforums.apple.com/thread/235803 (dead link as of 2018-01-26).
祝您好运。
这篇关于UISearchController:searchBar和scopeBar在第一次触摸事件时重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!