RealmResultsController
RealmResultsController copied to clipboard
Calling delegate methods in other queue delays rendering UITableView
I'm using RealmResultsControllerDelegate
as UITableViewDataSource
.
When beginning table view while scrolling, I see blank until stop scrolling.
I could fix this by updating table view in didChangeObject
at once like:
func didChangeResults(controller: AnyObject) {
guard controller === self.rrc else { return }
tableView.beginUpdates()
pendingChanges.forEach { update in
if let newIndexPath = update.newIndexPath, oldIndexPath = update.oldIndexPath {
switch update.changeType {
case .Delete:
tableView.deleteRowsAtIndexPaths([newIndexPath], withRowAnimation: .Automatic)
break
case .Insert:
tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Automatic)
break
case .Move:
tableView.deleteRowsAtIndexPaths([oldIndexPath], withRowAnimation: .Automatic)
tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Automatic)
break
case .Update:
tableView.reloadRowsAtIndexPaths([newIndexPath], withRowAnimation: .Automatic)
break
}
} else if let sectionIndex = update.sectionIndex {
let indexSet = NSIndexSet(index: sectionIndex)
switch update.changeType {
case .Delete:
tableView.deleteSections(indexSet, withRowAnimation: .Automatic)
break
case .Insert:
tableView.insertSections(indexSet, withRowAnimation: .Automatic)
break
case .Update:
tableView.reloadSections(indexSet, withRowAnimation: .Automatic)
break
default:
break
}
}
}
pendingChanges.removeAll()
tableView.endUpdates()
}
I think we should not call delegate method callbacks in different queues.
ref: https://github.com/ngs/ci2go/pull/33
Hi @ngs ,
I think I don't quite get what you say it is the source of the issue...
I think we should not call delegate method callbacks in different queues.
All the calls to the delegate methods occur on the main thread. So maybe the source of the problem is not that. Do you have more information about it?
BTW, sorry for the delay on replying to this issue
Just cloned your repo, checked out this commit: https://github.com/ngs/ci2go/commit/bf10a1cbdf782b457601cf823c08b31fe978c77a , which is the one before the https://github.com/ngs/ci2go/pull/33 PR was applied, and I am not having the issue you were showing me on the gif :confused: