I have a table view controller, when I press a cell, I load some data before displaying the view. When data are loaded, I push the view.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var post : Post = posts[indexPath.row] as Post
self.selectedPost = post
var alert:UIAlertController = ISAMContext.sharedInstance.alertDownloadInProgress("DOWNLOADING", sender:self)
let request:NSURLRequest=NSURLRequest(URL:imageUrl)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
if error == nil {
self.comments=self.api.getCommentsData(post)
dispatch_async(dispatch_get_main_queue(), {
if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
alert.dismissViewControllerAnimated(true, completion: {
self.performSegueWithIdentifier("postview", sender: self)
})
}
})
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "postview" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
let destination = (segue.destinationViewController as UINavigationController).topViewController as PostViewController
destination.post=selectedPost!
destination.comments=comments!
destination.delegate=self
}
}
}
I have some troubles with the height of an UITextView. I would like adjust the height depending on the length of the string (see my other question: How to adjust the height of a textview to his content in SWIFT?)
I found a way, calling sizeThatFits in viewDidAppear:
override func viewDidAppear(animated: Bool) {
let contentSize = postTextView.sizeThatFits(postTextView.bounds.size)
var frame = postTextView.frame
frame.size.height = contentSize.height
postTextView.frame = frame
}
It works, but as I call my code in viewDidAppear, I can see the view appears THEN the height of textView is updated.
- Press on a cell
- Load data
- Push the view
- Display the view
- THEN adjust the height of the textview -> I can see the height change
So my question is : It's possible to completely load a view (content and display) before pushing it ?