【发布时间】:2015-09-17 04:40:24
【问题描述】:
我有一个带有自定义视图单元格的UITableViewCell。
在这个视图单元格中,我有一个名为 imgWrapper 的简单 UIView,我在其中添加了如下约束:
- 宽度 = 50
- 高度 = 50
- 导致superview = 20
- top to superview = 20
- 从底部到超级视图 = 20
这些是那里唯一的限制。我把拥抱和压缩留给了默认的。
在我的代码中我设置了这个:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 90
}
然后在我的 rowAtIndex...我有这个:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: LogCustomCell = tableView.dequeueReusableCellWithIdentifier("logCustomCell", forIndexPath: indexPath) as! LogCustomCell
var imgWrapperHeight: CGFloat = log.big ? 100 : 50
cell.imgWrapperHeight.frame.size.height = imgWrapperHeight
return cell
}
一旦我编译并运行它。所有单元格的大小都相同。
注意事项:
- 我检查了 log.big 是否为真/假,并且确实发生了变化。
- 我也尝试过
CGRect(x,y,width,height),但也没有成功。 - 我知道我可以做
heightForRowAtIndexPath,但我想做动画,我知道我们可以为标签做这样的事情(见打印屏幕),这使得 tableView 知道高度而不定义它:
知道我做错了什么吗?
【问题讨论】:
-
您必须删除高度约束或底部以查看约束,因为您的约束存在问题
标签: ios xcode swift uitableview autolayout