如何以编程方式更改UITableViewCell上的约束?

时间:2016-08-01 09:12:10

标签: ios swift uitableview constraints

在以下位置创建单元格时:

func tableView ( tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath ) -> UITableViewCell

事实证明cell.constraints.count等于0,即使包含单元格布局的xib包含它们。实现以下两个功能 - 我想象可能会在适当的时刻调用 - 产生类似的令人失望的结果:

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)

如果我无法访问约束,我怎么能更改

我在这做错了什么,拜托?谢谢。

2 个答案:

答案 0 :(得分:1)

IBOutlet课程中为您constraint制作UITableViewCell,然后在cellforrowatindexpath方法中进行更改。

例如:cellforrowatindexpath

cell.texlabel.topspace.constant = 100;

答案 1 :(得分:1)

尝试使用

cell.contentView.constraints

对我有用!

相关问题