RealmResultsController icon indicating copy to clipboard operation
RealmResultsController copied to clipboard

Calling delegate methods in other queue delays rendering UITableView

Open ngs opened this issue 9 years ago • 2 comments

I'm using RealmResultsControllerDelegate as UITableViewDataSource.

When beginning table view while scrolling, I see blank until stop scrolling.

01

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()
}

source

I think we should not call delegate method callbacks in different queues.

ref: https://github.com/ngs/ci2go/pull/33

ngs avatar Jan 23 '16 22:01 ngs

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

polqf avatar Feb 11 '16 11:02 polqf

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:

polqf avatar Feb 11 '16 12:02 polqf