SwiftHN icon indicating copy to clipboard operation
SwiftHN copied to clipboard

Table View scrolling stops when datasource is updated

Open finder39 opened this issue 10 years ago • 5 comments

In NewsViewController.swift function loadMore()

https://github.com/Dimillian/SwiftHN/blob/master/SwiftHN/ViewControllers/NewsViewController.swift#L72

finder39 avatar Aug 01 '14 00:08 finder39

Tried a couple things

self.datasource = tempDatasource
self.tableView.reloadData()
self.tableView.beginUpdates()
tempDatasource.addObject(posts[0] as Post)
self.datasource = tempDatasource
self.tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: self.datasource.count-1, inSection: 0)], withRowAnimation: UITableViewRowAnimation.Fade)
self.tableView.endUpdates()

tried wrapping in GCD

dispatch_async(dispatch_get_main_queue(), {
}

All to no avail :/ I am curious if the issue is that it is a UITableViewDelegate subclass and self.datasource is an NSArray instead of setting it to an NSMutableArray that can be updated and calling reloadData()

finder39 avatar Aug 01 '14 00:08 finder39

I know exactly what it is. This is the cache write which is not multi threaded. I tried to dispatch it but for some reason I'm getting an unknown error with Swift. I'll wait for beta 5.

https://github.com/Dimillian/HackerSwifter/blob/master/Hacker%20Swifter/Hacker%20Swifter/HTTP/Cache.swift#L126

This call should be put on a background queue.

Well, it's also the model HTML scrapping, I'll dispatch all that in a later version. No more scroll stop :)

Dimillian avatar Aug 01 '14 07:08 Dimillian

Ya, that is definitely a strange error while trying the following there

   public override func setObject(object: AnyObject, key: String) {
        dispatch_async(dispatch_get_global_queue(self.priority, UInt(0)), {
            NSKeyedArchiver.archiveRootObject(object, toFile: self.fullPath(key))
        })
    }

finder39 avatar Aug 03 '14 19:08 finder39

I have made is successfully compile and work with tests in https://github.com/Dimillian/HackerSwifter/pull/12

It doesn't seem to fix the scroll stop, I will keep looking into it.

finder39 avatar Aug 03 '14 19:08 finder39

Is this bug still there or its been fixed??

Rokimkar avatar Jul 09 '16 09:07 Rokimkar