【发布时间】:2017-09-11 20:36:59
【问题描述】:
在我们的项目中,我们指定了
hidesNavigationBarDuringPresentation = false
在特定的UIViewController 的UISearchController 上。 searchController 有一个范围标题数组。到目前为止,这在 iOS 10 上运行良好,但在 iOS 11 测试版中,看起来 hidesNavigationBarDuringPresentation 的错误设置被忽略并扰乱了我们的显示。为了确保它不是因为我的项目中的其他因素,我创建了一个只有一个 UITableViewController 的准系统测试项目,其中一个 UISearchController 用另一个简单的 UITableViewController 初始化。以下代码在主视图控制器的viewDidLoad() 方法中:
self.title = "Search Bar Scope Test"
let searchViewController = SearchViewController(style: .plain)
searchController = UISearchController(searchResultsController: searchViewController)
searchController!.searchBar.sizeToFit()
tableView.tableHeaderView = searchController!.searchBar
searchController?.hidesNavigationBarDuringPresentation = false
searchController?.searchBar.scopeButtonTitles = ["scope 1", "scope 2", "scope 3", "scope 4", "scope 5"]
当分配scopeButtonTitles 的最后一行不存在时,导航栏没有隐藏,搜索栏保持在原来的位置。然而,随着那条线的出现,NavigationBar 被隐藏,searchBar 加上范围按钮在 iPhone 和 iPad 上都在纵向模式下向上移动,但在横向模式下保持不变(即使范围按钮很多并且一行都放不下)。
有没有其他人遇到过这种情况?这是 iOS 11 中的错误或预期行为(当然不是我们想要的行为),是否有任何解决方法?
谢谢!
【问题讨论】:
-
我的范围按钮没有问题,但我的整个搜索栏跳出表格视图并附加到屏幕顶部。使用 Xcode 9 GM。
-
@ChrisPaveglio 我终于找到了问题的原因。请参阅下面的答案。
-
谢谢,但这不是我的问题。我需要更多时间来弄清楚 b/c 我认为它更独特。我有一个 iPad 布局,有 2 个并排的表格视图,1 个有搜索栏,它永远不应该离开它的表格视图。我想在我更进一步之前我需要重构一些东西。
标签: ios ios11 xcode9-beta xcode9beta6