Skip to content

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

Description

@gotnull

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions