使用新的 iOS 11 时似乎会发生奇怪的事情navigationItem.searchController
详细视图的方法UISplitViewController
.
The searchBar
在第一个演示文稿中部分显示为空白,然后出现在错误的位置UITableViewController
,但在几次推入和弹出后会自行纠正UITableViewController
.
我曾经把searchBar
in the tableHeaderView
,但我根据WWDC的建议更改了代码:
if (@available(iOS 11.0, *)) {
self.navigationItem.searchController = self.searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
} else {
self.tableView.tableHeaderView = self.searchController.searchBar;
}
此示例使用标准示例代码(默认项目UISplitViewController
和苹果演示UISearchController
针对 iOS 11 进行了更新(使用单个UITableViewController
)).
初始视图包含searchController
看起来像这样:
![enter image description here](https://i.stack.imgur.com/IVZKM.png)
并单击UITableView
项目产生这个:
![enter image description here](https://i.stack.imgur.com/Y5uxl.png)
然而,点击后UITableView
项目并返回两次 - 它看起来应该是:
![enter image description here](https://i.stack.imgur.com/LFjyP.png)
and:
![enter image description here](https://i.stack.imgur.com/KouAg.png)
我试图确定为什么苹果的例子UISearchController
有效,但我的代码没有。主要区别在于它嵌入在UISplitViewController
在详细信息视图中。这意味着如果以紧凑模式显示,则有一个额外的UINavigationController
在堆栈中。我发现如果我的连续剧避免了额外的UINavigationController
- 它工作正常(但会破坏设备旋转)。同样,将 segue 更改为模态允许其工作。
![enter image description here](https://i.stack.imgur.com/J9q9l.png)
我注意到这与这个老问题类似:UISplitViewController 与 UISearchBar 的新 UISearchController 问题
我创建了一个示例项目来演示该问题(示例代码:searchController 演示)
我对发生的事情感到困惑。因此,我们将非常感谢任何帮助。