【问题标题】:Adapt the length of UITableViewCell to that of the UITableView使 UITableViewCell 的长度适应 UITableView 的长度
【发布时间】:2016-04-19 10:12:24
【问题描述】:

这是我的第一个 swift 项目,我尝试制作一个应用内设置页面。 所以我有一个基本的 UITabelView,里面有自定义的 UITableViewCell。我的 UITableViewCell 包含左侧的 UILabel 和右侧的 UISwitch。

问题是 UITableViewCell 长度是静态的(我认为),当我在 iPhone 6 上编译时,结果如下:

当我在 iPad 空气模拟器上编译时,我没有单元格。

那么如何动态调整 UItableViewCell 的长度呢?

【问题讨论】:

  • 你好像没有使用自动布局?
  • 不,我不使用?我必须?
  • 你设置了布局约束吗
  • 你不需要,但你应该。你可以用 springs+struts 做到这一点,但自动布局是未来......
  • 好的,我会阅读自动布局的文档,谢谢

标签: ios swift uitableview uiswitch


【解决方案1】:

这里有一个简单的修复方法。

在您的 TableCell.m 中

在创建 UISwitch 时添加它

目标-c:

switch.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;

斯威夫特:

switch.autoresizingMask = .FlexibleLeftMargin;

【讨论】:

    猜你喜欢
    • 2021-11-19
    • 2016-04-22
    • 2023-03-26
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多