[英]Creating 2 dynamic cell prototypes in my ios swift TableView with different heights
我必须使用2个原型单元在swift中创建一个UIView表,每个单元具有不同的高度。 我的第一个单元格只有一个标签和一个按钮在同一行,所以它的高度不应该太多。 第二个细胞将有图像,4个标签等,所以我需要高度。 有没有办法可以在代码或IB中更改动态tableview单元格的高度?
谢谢!
将控制器设置为UITableView
delegate
。 然后实现可选功能
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == 0
return 180
else
return 40 }
你能使用这个功能:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
// return height for each cell
}
对不起,如果我误解了这个问题。
func tableView(tableView:UITableView,heightForRowAtIndexPath indexPath:NSIndexPath) - > CGFloat {
这是一种可用于根据作为表视图委托方法的索引路径设置所有单元格高度的方法。 以编程方式设置单元格的高度。 如果要通过Ui设置高度,可以为所有单元格设置静态高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.