gpt4 book ai didi

ios - 快速调整自定义单元格大小时遇到​​问题

转载 作者:行者123 更新时间:2023-11-30 13:46:35 27 4
gpt4 key购买 nike

所以我使用 Parse 后端构建了一个简单的信使。在 tableView 中,我显示用户之间的对话。 tableView 中的单元格根据标签上的文本量调整大小。

我在 viewDidLoad() 中使用此代码来实现调整大小:

tableView.estimatedRowHeight = 51
tableView.rowHeight = UITableViewAutomaticDimension
tableView.setNeedsLayout()
tableView.layoutIfNeeded()

我使用的估计高度为 51,因为这是 Storyboard上单元格的高度。不管怎样,我面临的问题是,有时单元格的大小不正确,有时对于它们所容纳的内容来说显得太大。我不明白为什么。这是单元格的错误渲染 .

这是我通过简单地上下滚动来实现的单元格的稍微正确的渲染。

.

这是怎么回事?

最佳答案

remove this lines from viewDidLoad

1)tableView.estimatedRowHeight = 51
2)tableView.rowHeight = UITableViewAutomaticDimension

use below two methods of tableview

override func tableView(tableView:UITableView, heightForRowAtIndexPath indexPath:NSIndexPath)->CGFloat
{
return UITableViewAutomaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return UITableViewAutomaticDimension
}

关于ios - 快速调整自定义单元格大小时遇到​​问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34847224/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com