在UITableView中隐藏空单元格 [英] Hide empty cells in UITableView
问题描述
我有一个可搜索的tableview,但是只想显示用户开始搜索后返回的单元格数。例如,如果用户键入charecter并且只有一个单元格与搜索匹配,则剩余单元格表格的其余单元格为空。我想知道是否有办法隐藏那些空单元格。我还想知道如果一个人的搜索与任何数据都不匹配,是否有办法隐藏表格视图(默认情况下,它会显示一个空单元格表,显示无结果)。
I have a searchable tableview, but would like to only display the number of cells that are returned once a user starts a search. For instance, if a user types in a charecter and there is only one cell that matches the search, the remaining cells the remaining cells of the table are empty. I was wondering if there is a way to hide those empty cells. I was also wondering if there is a way to hide the table view if a person's search does not match any data (by default, it displays a table of empty cells saying "No Results").
谢谢。
推荐答案
在数据源中更改 tableView:numberOfRowsInSection:
的实现返回搜索结果的数量而不是项目的总数。然后使用搜索结果而不是其余数据填充这些单元格。
Change your implementation of tableView:numberOfRowsInSection:
in your data source to return the number of search results instead of the total number of items. Then populate those cells with the search results instead of with the rest of the data.
这篇关于在UITableView中隐藏空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!