一些具有动态高度的tableview单元格,其他具有固定高度的单元格 [英] Some tableview cells with dynamic height, other with fixed height

查看:170
本文介绍了一些具有动态高度的tableview单元格,其他具有固定高度的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子.我想要一些具有动态高度的tableview单元格,而另一些具有固定高度的单元格.对于动态高度,我在viewDidLoad视图控制器委托中使用了以下几行.

I have a tableview. I want some tableview cells with dynamic height while other cells with the fixed height. For dynamic height, I used following lines in my viewDidLoad view controller delegate.

tableView.estimatedRowHeight = 200
tableView.rowHeight = UITableViewAutomaticDimension

在一个表格视图中具有固定高度的单元格和自定义大小的单元格的有效方法是什么?

what will be the efficient way to have fixed heighted cells and self sizing cells in one tableview?

谢谢.

推荐答案

Swift 3

您可以重新运行动态&通过这样做,在tableview中的静态单元格高度

You can retrun dynamic & static cell height in a tableview by doing this

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    if indexPath.row == 0 {
        return 120.0 // for static cell height
    }
    else {
        return UITableViewAutomaticDimension // for dynamic cell height
    }
}

您必须像这样实现另一个表视图估计的HeightHeightForRowAt方法

You have to implement another tableview estimatedHeightForRowAt method like that

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {

    if indexPath.row == 0 {
        return 120.0
    }
    else {
        return UITableViewAutomaticDimension
    }
}

别忘了将标签lineNumbers设置为0& ;; lineBreakMode哪个标签将动态扩展&最重要的是,不要将标签高度设置为固定.

Don't forget to set label lineNumbers to 0 & lineBreakMode which label will expand dynamically & most importantly don't set the label height fixed.

这篇关于一些具有动态高度的tableview单元格,其他具有固定高度的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆