Ios 从collectionViewCell内的tableView重新加载数据
我在Ios 从collectionViewCell内的tableView重新加载数据,ios,uitableview,swift3,uicollectionviewcell,tableviewcell,Ios,Uitableview,Swift3,Uicollectionviewcell,Tableviewcell,我在collectionViewCell中有一个tableView,在尝试重新加载数据时出错 *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.6.21/UITableView.m:1610 我尝试使用Dispatch.main.async,似乎解决了这个问题。唯一
collectionViewCell
中有一个tableView
,在尝试重新加载数据时出错
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.6.21/UITableView.m:1610
我尝试使用Dispatch.main.async
,似乎解决了这个问题。唯一的问题是它不会重新加载数据,并且表视图中没有任何更改
func cleanItems(completion: @escaping (Bool) -> Void) {
Dispatch.main.async {
cell.tableView.beginUpdates()
// Make changes in the Data Source
cell.tableView.deleteRows(at: selectedItems, with: .fade)
cell.tableView.endUpdates()
// Reloading sections accordingly depending on what the user has deleted
// Do I need to reload data here again? It used to work without Dispatch, but it wasn't stable
cell.tableView.reloadData()
// Updating items with if statements to reload data in Firebase
completion(true)
}
}
这根本不会重新加载数据,而且似乎没有任何变化。好的是我没有遇到随机崩溃,这是在实现Dispatch.main.async
我检索了每个部分中的numberOfRows
,以查看在结束更新后有多少行
print(cell.tableView.numberOfRows(inSection: 1))
我得到的行数与当前视图中的行数相同
这是至关重要的,因为如果tableView
部分都为零,那么collectionViewCell
应该消失。我们从未在completion
块中找到这里,因为它说numberOfRows
从未改变过。留给我们一个未更新的表视图
我通过将Dispatch.main.async
移到函数调用之外解决了这个问题
Dispatch.main.async {
cleanItems(completion: { (success) in
etc.
})
}
您还需要从数组中删除对象。我已经在实际代码中这样做了,我只是简化了这里的结构。我这样做的方式是获取selectedIndexPaths并应用过滤器删除selectedIndexPaths上的项目。