我制作了一个包含 UISearchController
和 UITableView
的 UIViewController
。 UITableView 最初会显示所有结果,然后每当用户开始输入内容时,这些结果都会通过 UISearchController 进行过滤。单击每个单元格应链接到详细页面。虽然这在用户尚未开始输入时有效,但一旦用户开始输入,即当 UISearchController 开始显示结果时,它就不再有效。这就是我在控制台中得到的全部内容:
Warning: Attempt to present <MyProject.profileView: 0x13e9df000> on <MyProject.SearchPage: 0x142a1d8f0> which is already presenting <UISearchController: 0x142a1f7c0>
这让我认为 UISearchController 实际上正在呈现第二个 UITableView,其中包含第一个 UITableView 的过滤结果,我认为这应该是导致错误的原因。不过,我并不完全确定。
这就是我将 UISearchController
添加到我的 UIViewController
的方法:
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
self.definesPresentationContext = true
searchController.searchBar.scopeButtonTitles = ["Groups", "People"]
searchController.searchBar.delegate = self
tableView.tableHeaderView = searchController.searchBar
如果您知道可能导致此问题的原因和/或我如何解决它,请告诉我,我将不胜感激。提前致谢。
最佳答案
在这个问题上被困了大约两周后,我发现解决方案实际上非常简单。我只需要从 UISearchController
而不是从主 UIViewController
呈现 UIViewController
。这行代码修复了它:
self.searchController.presentViewController(vc, animated: false, completion: nil)
关于ios - UISearchController 与 UITableView 重叠,这使我无法为单元格呈现详细的 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36951129/