ios - 将 UITableViewCell 的长度调整为 UITableView 的长度

标签 ios swift uitableview uiswitch

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

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

enter image description here

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

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

最佳答案

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

在您的 TableCell.m 中

在创建 UISwitch 时添加此内容

objective-c :

switch.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;

swift :

switch.autoresizingMask = .FlexibleLeftMargin;

关于ios - 将 UITableViewCell 的长度调整为 UITableView 的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36715321/

相关文章:

ios - 匿名闭包参数不能在具有显式参数的闭包内使用

ios7中的UITableViewCell现在左右有间隙

ios - 集成:我应该为图像选择哪种类型的全局标识符?

ios - 重叠 TableView 在其后面滚动 TableView

swift - 数据建模和初始化中的私有(private)属性

ios - 我想要 collectionView 中的表节标题索引或节标题标题(_ :cellForItemAt:)

ios - 使用显示/更少按钮展开/折叠表格 View 单元格

iphone - 将 UIButton 编程为切换

ios - iOS中系统查杀应用和用户查杀应用的区别

swift - 命令因信号 : Segmentation fault: 11 after upgrade to Xcode 8 and Swift 3 而失败