推送新的 UIViewController 时 UISearchController 消失

Posted

技术标签:

【中文标题】推送新的 UIViewController 时 UISearchController 消失【英文标题】:UISearchController disappears when pushing a new UIViewController 【发布时间】:2018-11-09 03:08:34 【问题描述】:

我目前正在使用 Raywenderlich 的示例:UISearchController-Tutorial(完成的项目在他们文章的末尾或here),我注意到当我执行搜索并单击其中一个结果时,在推送过渡期间, UISearchController 消失。在此视频中可见:here

Before selecting a result

During the transition to the new VC

我使用 Xcode 10、ios 12(sim:iPhone 8)运行此示例

任何想法/指针将不胜感激

干杯。

【问题讨论】:

你能分享任何代码吗,很难说!当你展示你的detailviewcontroller时,你是否为detailviewcontroller设置definesPresentationContext = true?如果您不设置,您可能会看到一些奇怪的行为。 @lionserdar,感谢您的评论。该代码可从我发布的链接下载。设置 definesPresentationContext 并不能解决问题。 【参考方案1】:

iOS12 的默认设置。看看 Apple-Mail 应用程序。那里是一样的。实际上,当您显示另一个 VC 时,您不需要搜索栏

【讨论】:

感谢您的回答。当用户点击结果并推送新的 VC 时搜索器消失的事实在视觉上并不好。

以上是关于推送新的 UIViewController 时 UISearchController 消失的主要内容,如果未能解决你的问题,请参考以下文章

UINavigationController 中的 UIScrollView 中的 UIViewController 想要推送新的控制器

内容后面的 UIViewController 中的黑屏

推送 UIViewController 时如何更改 TabBarItens?

从导航堆栈推送/弹出uiviewcontroller时如何收到警报

推送 UIViewController 时不能在类型上使用实例成员

推送 UIViewController 崩溃