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

标签 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)

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

请问我做错了什么?谢谢。

最佳答案

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

例如:在cellforrowatindexpath

cell.texlabel.topspace.constant = 100;

关于ios - 如何以编程方式更改 UITableViewCell 上的约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38694986/

相关文章:

swift - Sprite 的随机移动

ios - 检测 tableView 中每个部分的最后一个单元格

ios - 在 ViewController 之间共享网络数据模型的设计模式

java - CodeName1 - ipa 和源代码之间的不同响应代码

iphone - 我无法在 iTunes Connect 中获得崩溃报告

ios - 使用 AutoLayout 在 UIScrollView 底部查看

swift iOS : iAd not populating

ios - 将 UILabel 子类从 Objective-C 转换为 Swift

ios - 如何在 iOS 中播放 .mts 文件

ios - 带约束的嵌套 Collection View 的意外行为 (Swift 4)