当查询为空时,UISearchController隐藏tableView

时间:2019-06-03 00:28:02

标签: swift uisearchcontroller

不知何故,当我的搜索字符串为空时,即使我的数据数组仍然保存信息并且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 = false,但应该有一个更好的方法,例如hideTableViewWhenSearchEmpty或类似的方法。

谢谢!

0 个答案:

没有答案
相关问题