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

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.

Example code:
First Load (from callback method):
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.