首页 > 解决方案 > UISearchController 在查询为空时隐藏 tableView

问题描述

不知何故,当我的搜索字符串为空时,即使我的数据数组仍然保存信息并且numberOfRowsInSection/numberOfSections仍然返回相应的信息,tableView 也被隐藏了。
我将此代码放入我的UISearchResultsUpdating(searchResultsUpdater):

func updateSearchResults(for searchController: UISearchController) {
    print(tableView.isHidden)
    // my program logic to fetch data with that string from server
    // and reload the tableView
}

它明确指出,一旦我删除搜索栏中的所有文本,该isHidden属性就会设置为。 现在,在你可以看到的确切位置,我放了,但应该有更好的方法,类似或沿着这些思路。true
print()tableView.isHidden = falsehideTableViewWhenSearchEmpty

提前致谢!

标签: swiftuisearchcontroller

解决方案


推荐阅读