Dimillian / SwiftHN

A Hacker News reader in Swift
GNU General Public License v2.0
1.71k stars 282 forks source link

Table View scrolling stops when datasource is updated #19

Open finder39 opened 10 years ago

finder39 commented 10 years ago

In NewsViewController.swift function loadMore()

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

finder39 commented 10 years ago

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

Dimillian commented 10 years ago

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 :)

finder39 commented 10 years ago

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 commented 10 years ago

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.

Rokimkar commented 8 years ago

Is this bug still there or its been fixed??