简体   繁体   English

Tableview单元格大小没有变化? 迅速

[英]Tableview Cell size not changing? Swift

I dragged an dropped a table view Controller from the object library and changed the cell's row height to 300.However , when I run it in the simulator , the cell remains the same standard size.Why is this? 我从对象库拖动一个表格视图控制器,并将单元格的行高改为300.但是,当我在模拟器中运行它时,单元格保持相同的标准尺寸。为什么这样?

Images : 图片 在此输入图像描述 在此输入图像描述

Constraints : 制约因素 在此输入图像描述

Output : 输出 在此输入图像描述

In Storyboard, if you know the cell height, set the Table View's Row Height property on the Size Inspector tab, not the cell's: 在Storyboard中,如果您知道单元格高度,请在“大小检查器”选项卡上设置“表视图”的“行高”属性,而不是单元格的:

UITableView的Size Inspector页面

You can set custom row height example add ; 您可以设置自定义行高示例添加;

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
{
    return 100.0;//Your custom row height
}
  1. Make sure you have given all the constraints in the cell . 确保您已在单元格中给出所有约束。 They have to be connected from top to bottom. 它们必须从上到下连接。

  2. Make sure that the class of content view inside the custom cell is UIView .(I have done the same mistake ) 确保自定义单元格中的内容视图类是UIView。(我犯了同样的错误)

    press content view -> see identity inspector on right -> class should be UI view . 按内容视图 - >查看右侧的身份检查器 - >类应该是UI视图。 自定义单元格元素

使用tableview的委托并设置heightforrowatindexpath方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM