두 섹션이있는 UITableView
있습니다. 각 섹션에는 특정 영역 객체에 대한 쿼리 결과가 표시됩니다.그룹화 된 UITableView 및 영역 알림
var contentRequests: Results<UESocketPostRequest>? {
return try? CustomRealm.realm().objects(UESocketPostRequest.self).filter("completed = false AND content != nil").sorted(byKeyPath: "content.createdAt", ascending: false)
}
var mediaUploads: Results<UEMediaUploadRequest>? {
return try? CustomRealm.realm().objects(UEMediaUploadRequest.self).filter("finished = false").sorted(byKeyPath: "media.content.createdAt", ascending: false)
}
내 UITableViewDelegate
및 UITableViewDataSource
적합성 :
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
return self.contentRequests?.count ?? 0
case 1:
return self.mediaUploads?.count ?? 0
default:
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "UPLOADCELL") as? UEUploadCell else {
return UITableViewCell()
}
switch indexPath.section {
case 0:
if let request = self.contentRequests?[indexPath.row] {
cell.softBindSocketRequest(request)
}
case 1:
if let request = self.mediaUploads?[indexPath.row] {
cell.softBindMediaUploadRequest(request)
}
default:
break
}
return cell
}
그때 내 영역 결과 각각 NotificationToken
년대를 설정하고이 같은 테이블 뷰 업데이트 : 자주
func startContentToken() {
self.contentToken = self.contentRequests?.observe({ [weak self] (changes) in
switch changes {
case .error:
break
case .initial:
let indexSet = IndexSet(integer: 0)
self?.tableView.reloadSections(indexSet, with: .automatic)
case .update(let content, deletions: let deletions, insertions: let insertions, modifications: let modifications):
self?.tableView.beginUpdates()
self?.tableView.insertRows(at: insertions.map({ IndexPath(row: $0, section: 0) }),
with: .automatic)
self?.tableView.deleteRows(at: deletions.map({ IndexPath(row: $0, section: 0)}),
with: .automatic)
self?.tableView.reloadRows(at: modifications.map({ IndexPath(row: $0, section: 0) }),
with: .automatic)
self?.tableView.endUpdates()
}
})
}
func startMediaToken() {
self.mediaToken = self.mediaUploads?.observe({ [weak self] (changes) in
switch changes {
case .error:
break
case .initial:
let indexSet = IndexSet(integer: 1)
self?.tableView.reloadSections(indexSet, with: .automatic)
case .update(let media, deletions: let deletions, insertions: let insertions, modifications: let modifications):
self?.tableView.beginUpdates()
self?.tableView.insertRows(at: insertions.map({ IndexPath(row: $0, section: 1) }),
with: .automatic)
self?.tableView.deleteRows(at: deletions.map({ IndexPath(row: $0, section: 1)}),
with: .automatic)
self?.tableView.reloadRows(at: modifications.map({ IndexPath(row: $0, section: 1) }),
with: .automatic)
self?.tableView.endUpdates()
}
})
}
I을 이 로그 메시지 또는 유사하게 캡슐화 된 UITableView
불일치 예외로 인해 충돌이 발생합니다.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
내가 뭔가 잘못하고 있는가 또는 영역이 방법으로 그룹화 UITableView
의 함께 사용하도록 설계되지 않는 이유는 무엇입니까?
통찰력을위한 감사합니다 Jeroen. 해결 방법을 찾을 수 있는지 알아보기 위해 조금 놀아 보겠습니다. –
@JonVogel 솔루션을 제안 했습니까? – sirvon
아니요.하지만 여기 제가 Realm 코코아 저장소에 제기 한 문제가 있습니다 : https://github.com/realm/realm-cocoa/issues/5553 –