UISearchController 模态呈现样式错误

UISearchController Modal Presentation Style Error

我正在以编程方式将 UISearchController 添加到 UIStackView,它作为子视图嵌入到更大的视图中,我正在将其添加到 UITableViewController 中的 UITableViewCell。

我将 UITableViewController 设置为搜索栏委托、更新程序委托和搜索控制器委托。

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

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 的问题。