Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On first load the image appears halfway down until you first scroll (either up or down) from a callback. #17

Open
gotnull opened this issue Jul 3, 2014 · 4 comments

Comments

@gotnull
Copy link

gotnull commented Jul 3, 2014

Example code:

func getPhoto(callback: (Array<AnyObject>) -> ()) {
    let urlPath: NSString = "some_rest_url"
    let url = NSURL(string: urlPath)

    let request = NSMutableURLRequest(URL: url)
    request.HTTPMethod = "GET"
    request.addValue("application/json", forHTTPHeaderField: "Accept")

    let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(), delegate: self, delegateQueue: NSOperationQueue.mainQueue())

    var dataTask = NSURLSessionDataTask()
    dataTask = session.dataTaskWithRequest(request) { (data, response, error) in
        if (error == nil) {
            callback(array)
        }
    }
    dataTask.resume()
}

override func viewDidLoad() {
    super.viewDidLoad()

    // Works fine here with any image.
    //let venueImage = UIImage(named: "bg")
    //self.tableView.addParallaxWithImage(venueImage, andHeight: 160)

    // Bug occurs here, when coming from callback.
    api.getPhoto() { (photos) in
        let photo = photos[0] as FSPhoto
        let data = NSData(contentsOfURL: NSURL.URLWithString("\(photo.prefix)300x300\(photo.suffix)"))
        let venueImage = UIImage(data: data)
        let venueImage = UIImage(named: venueImage)
        self.tableView.addParallaxWithImage(venueImage, andHeight: 160)
    }
}

First Load (from callback method):

Image of Problem

When scrolling for the first time (either up or down), the image appears where it should be.

The image appears properly otherwise if it's just a simple call within the viewDidLoad.

Image of Fixed

@gotnull gotnull changed the title On first load image appears halfway down until first scroll (either up or down) On first load image appears halfway down until first scroll (either up or down) from delegate method. Jul 3, 2014
@gotnull gotnull changed the title On first load image appears halfway down until first scroll (either up or down) from delegate method. On first load the image appears halfway down until you first scroll (either up or down) from a callback. Jul 3, 2014
@RishabhTayal
Copy link

I am having the same issue. Please help.

@johanbaath
Copy link

Same issue. Any updates?

@gotnull
Copy link
Author

gotnull commented Sep 29, 2014

Unfortunately I never received an update on this issue. Never managed to resolve it either.

On 29 Sep 2014, at 9:04 pm, Johan Bååth notifications@github.com wrote:

Same issue. Any updates?


Reply to this email directly or view it on GitHub.

@johanbaath
Copy link

A simple work-around is to move the contentOffset to the top in the viewDidLoad function.

Example:

self.tableView.contentOffset = CGPointMake(0, 0 - self.tableView.contentInset.top);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants