collectionViewCell
안에 tableView
이 있는데 데이터를 다시로드하려고하면 오류가 발생합니다.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
을 사용해 보았는데 문제가 해결 된 것 같습니다. 유일한 것은 그것이 전혀 데이터를 다시로드하지 않습니다 tableView
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)
}
}
이의 데이터와 아무것도 변화를 다시로드하지 않고 아무것도 변경 보인다는 것이다. 좋은 점은 무작위 충돌이 발생하지 않는다는 것입니다. 구현하기 전에 무언가가 발생하지 않습니다.
각 섹션에서 numberOfRows
을 검색하여 업데이트가 끝난 후 몇 행이 있는지 확인했습니다.
print(cell.tableView.numberOfRows(inSection: 1))
그리고 현재보기에있는 것과 동일한 수의 행을 가져옵니다.
tableView
섹션이 모두 0 일 경우 collectionViewCell
이 사라져야하기 때문에 이것은 매우 중요합니다. numberOfRows
은 절대로 변하지 않았으므로 결코 completion
블록에 도착하지 않습니다. 업데이트되지 않은 tableView
으로 우리를 떠나라.
배열의 개체도 삭제해야합니다. –
나는 실제 코드에서이를 수행했다. 여기서 구조를 단순화했다. 내가하는 일은 selectedIndexPaths를 가져 와서 selectedIndexPaths의 항목을 삭제하는 필터를 적용하는 것입니다. – Christian