swift - UISearchController 模式呈现样式错误

标签 swift user-interface ios12

我以编程方式将 UISearchController 添加到 UIStackView,它作为 subview 嵌入到更大的 View 中,我将其添加到 UITableViewController 中的 UITableViewCell。

我将 UITableViewController 设置为搜索栏委托(delegate)、更新程序委托(delegate)和搜索 Controller 委托(delegate)。

但是,当我将 UISearchController 添加到 View 时,出现此错误:

UISearchController only supports modal presentation styles UIModalPresentationPopover, UIModalPresentationFormSheet and UIModalPresentationCustom

然后,当我稍微尝试一下并设置此设置时:

searchController.modalPresentationStyle = .popover

然后我收到此错误:

Presenting UISearchController in a popover or form sheet while reusing the search origin as the search results destination makes little sense. Initialize UISearchController with a proper search results controller to present as a popover or in a form sheet

这些错误意味着什么?

最佳答案

改变

let searchController = UISearchController()

let searchController = UISearchController(searchResultsController: myViewController)

为我解决了 myViewController 继承自 UIViewController 的问题。

关于swift - UISearchController 模式呈现样式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56914235/

相关文章:

swift - Alamofire 3.0 请求

ios - 如何更改 UIViewController 内 UITableView 页脚的背景颜色?

linux - 如何将图像配置为主题中的按钮

xcode - 由 Xcode 版本 13 构建的应用程序在 ios 12 上崩溃

ios - 如何淡出 iOS 12 上的 titleView 标签

ios - SpriteKit/Swift 中向上滑动角色跳跃

ios - Swift UIWebView 并不总是有效

java - 效率计数器不会重置

c++ - 如何动态创建与其父控件具有相同视觉样式的控件?

ios - iOS 12-NSFaceIDUsageDescription突然不起作用