【发布时间】:2015-04-11 10:24:18
【问题描述】:
我有一个表格视图控制器,当我按下一个单元格时,我会在显示视图之前加载一些数据。加载数据后,我推送视图。
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
}
}
}
UITextView 的高度有些问题。我想根据字符串的长度调整高度(见我的另一个问题:How to adjust the height of a textview to his content in SWIFT?)
我找到了一种方法,在 viewDidAppear 中调用 sizeThatFits:
override func viewDidAppear(animated: Bool) {
let contentSize = postTextView.sizeThatFits(postTextView.bounds.size)
var frame = postTextView.frame
frame.size.height = contentSize.height
postTextView.frame = frame
}
它可以工作,但是当我在 viewDidAppear 中调用我的代码时,我可以看到视图出现然后 textView 的高度被更新。
- 按一个单元格
- 加载数据
- 推送视图
- 显示视图
- THEN 调整 textview 的高度 -> 我可以看到高度变化
所以我的问题是:可以在推送之前完全加载视图(内容和显示)吗?
【问题讨论】:
标签: ios uitableview swift segue viewdidappear