我正在使用UITableViewAutomaticDimension來讓我的TableViewCells自動調整內容大小。如果第一個單元格中有多行文本,它將採用正確的高度,但只顯示第一行內容,直到我向下滾動並備份。UILabel沒有立即獲取內容
該標籤在故事板中配置有:
ViewDidAppear:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.tableView!.estimatedRowHeight = 250
self.tableView!.rowHeight = UITableViewAutomaticDimension
ProgressHUD.show("Loading...", interaction: false)
let API = postAPI()
API.getNew() {
(result: [Post]?) in
ProgressHUD.dismiss()
if let ps = result {
if self.posts.count != ps.count {
self.posts.removeAll()
self.posts.appendContentsOf(ps)
self.tableView.reloadData()
}
} else {
ProgressHUD.showError("There was a problem getting new posts")
}
}
}
的cellForRowAtIndexPath:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("OMCFeedCell", forIndexPath: indexPath) as! OMCFeedTableViewCell
let p = posts[indexPath.row]
cell.selectionStyle = .None
let data = p.content!.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let content = try! JSON(NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers))
if let image = content["image"].string {
let uploads = uploadAPI()
uploads.tryGetImage(image) {
(result: UIImage?) in
if let i = result {
cell.postImage.contentMode = .ScaleAspectFit
cell.postImage.image = i
}
}
}
cell.postText.text = ""
if let text = content["text"].string {
cell.postText.text = text
}
return cell
}
投票欄上的約束:
你可以在你的'cellForRowAtIndexPath'中顯示代碼嗎?在Storyboard中如何配置標籤? – Paulw11
@ Paulw11我添加了相關的代碼和配置選項 –
認爲他們想看到約束。 – beyowulf