gpt4 book ai didi

ios - 应用于字幕 TableView 单元格的 UITableViewAutomaticDimension 无法正常工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:55:35 26 4
gpt4 key购买 nike

我正在为列表制作一个 View 。它在字幕中具有动态长度。所以我使用了 UITableViewAutomaticDimension 属性。我没有应用任何约束,因为这两个标签都是 TableView 单元格属性,因此无需创建新的自定义单元格。

但在运行这个项目后,我标记了 UITableViewAutomaticDimension 无法正常工作。我不知道我做错了什么。我的代码如下所示

view did load

@IBOutlet weak var tblabc: UITableView!
override func viewDidLoad() {
super.viewDidLoad()

tblabc.separatorColor = UIColor.clearColor()

tblabc.estimatedRowHeight = 44
tblabc.rowHeight = UITableViewAutomaticDimension



// Do any additional setup after loading the view.
}

table view delegate and data source

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell = tableView.dequeueReusableCellWithIdentifier("Cell")
if (cell == nil)
{

cell = UITableViewCell(style: .Subtitle, reuseIdentifier: "Cell")
cell?.selectionStyle = .None
cell?.detailTextLabel?.font = _SETREGULARFONT_KARLA(IS_IPAD ? 19:15)
cell?.textLabel?.font = _SETBOLDFONT_KARLA(IS_IPAD ? 17:13)
cell?.detailTextLabel?.textColor = getColorFromRGB(120, G: 132, B: 158, A: 1.0)
cell?.detailTextLabel?.numberOfLines = 0
cell?.detailTextLabel?.lineBreakMode = .ByTruncatingTail
cell?.selectionStyle = .None

}

cell?.textLabel?.text = "Testing" + "\(indexPath.row)"
cell?.detailTextLabel?.text = "tesfhjdsfskdfhjkfhdjskfhsjkdfhdjsxdfgfjljkgjfklgfhsdjfhjkdshfdjskfhdjfjkfhafyhdsifjhdjksfbshdjkfkhdksjfhdjsfyhds8ufdhsfjkhdsfjhdfudsiufhdsfh"
cell?.imageView?.image = UIImage(named: "new_temp")

return cell!
}

View looks like below image

enter image description here

最佳答案

当您有一个多行 detailTextLabel 时,内置 UITableViewCellStyles(所有这些!)的 UITableViewAutomaticDimension 高度计算基本上是“损坏的”。正如 Venkat Reddy 评论的那样,请在此处查看我的解决方案:Autolayout ignores multi-line detailTextLabel when calculating UITableViewCell height (all styles)

[具有适当权限的人应该考虑将此问题标记为重复]

关于ios - 应用于字幕 TableView 单元格的 UITableViewAutomaticDimension 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38975434/

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