清除 UITableView
Clearing out UITableView
我需要一种清除 UITableView 的方法。顺便说一句,我不能只清除数据源并重新加载 UITableView。我必须从 UITableView 中删除所有单元格。
I can't just clear out the data source and reload the tableview
嗯,这太糟糕了,因为这就是答案。清除数据源,或者至少抛出一个导致 numberOfSections
到 return 0
的标志 - 然后重新加载 table 视图。
I have to remove all the cells from the tableview
是的,嗯,如果你按照我刚才说的去做,就会发生这种情况。
试试下面的代码:
let cell = tableView.cellForRow(at: NSIndexPath(row: z, section: 0) as IndexPath) as! Cusotmcell
cell.contentView.removeFromSuperview()
其中 z
是单元格
的索引
我需要一种清除 UITableView 的方法。顺便说一句,我不能只清除数据源并重新加载 UITableView。我必须从 UITableView 中删除所有单元格。
I can't just clear out the data source and reload the tableview
嗯,这太糟糕了,因为这就是答案。清除数据源,或者至少抛出一个导致 numberOfSections
到 return 0
的标志 - 然后重新加载 table 视图。
I have to remove all the cells from the tableview
是的,嗯,如果你按照我刚才说的去做,就会发生这种情况。
试试下面的代码:
let cell = tableView.cellForRow(at: NSIndexPath(row: z, section: 0) as IndexPath) as! Cusotmcell
cell.contentView.removeFromSuperview()
其中 z
是单元格