【发布时间】:2015-11-19 02:09:45
【问题描述】:
我正在使用 UITableViewAutomaticDimension 让我的 TableViewCells 自动调整到内容的大小。如果我在第一个单元格中有多行文本,它会采用正确的高度,但只显示第一行内容,直到我向下滚动并向上滚动。
标签在情节提要中配置为:
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 我添加了相关代码和配置选项
-
认为他们想看到约束。
-
@beyowulf 也添加了这些。
-
什么是 postImage?它的限制是什么?
标签: ios swift uitableview