【发布时间】:2015-03-20 21:57:38
【问题描述】:
首先我想要什么。我想拥有随文本长度变化的动态高度的单元格。像图片中的东西:
如您所见,第二个单元格位于边缘上方。
我是怎么做到的?首先我有一个布局到边缘的表格:
我用自己的 xib 文件创建了自定义 SwitchCell:
标签具有以下自动布局设置:
然后切换这些:
在 viewDidLoad 中我设置了 tableView 属性:
tableView.registerNib(UINib(nibName: SwitchCellIdentifier, bundle: NSBundle.mainBundle()), forCellReuseIdentifier: SwitchCellIdentifier)
tableView.tableFooterView = UIView(frame: CGRectZero)
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = 44.0;
在 cellForRowAtIndexPath 我有这个:
...
var cell:SwitchCell = tableView.dequeueReusableCellWithIdentifier(SwitchCellIdentifier) as SwitchCell
cell.titleLabel.text = "Receive payments via multipay and lorem ipsum bla bla"
return cell
那么我做错了什么?我应该更改或添加什么?
【问题讨论】:
-
您能进入 xcode 的可视化调试器,向我们展示单元格的层次结构吗?此外,您是否在日志中收到任何“约束被破坏”的消息?
标签: ios uitableview swift autolayout