我以编程方式将 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/