不知何故,当我的搜索字符串为空时,即使我的数据数组仍然保存信息并且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
或类似的方法。
谢谢!