【发布时间】:2015-12-06 08:24:50
【问题描述】:
我正在尝试为我的UITableViewCell 设置自定义高度。在 Xcode 中,我给了它一个自定义高度并添加了一个 UImageView 子视图,它看起来很好。但是在运行时,单元格的高度会回落到默认值,并且我的图像被严重裁剪。
我已将委托设置为使用动态高度,并且在 Xcode 中为单元格提供了自定义高度,并且我的图像设置为 Aspect Fill。我不确定我还缺少什么。
这是我的vc:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
switch indexPath.section {
case 0:
return UITableViewAutomaticDimension
default: ()
return 50
}
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
switch indexPath.section {
case 0:
return 300
default: ()
return 50
}
}
【问题讨论】:
标签: ios swift uitableview autolayout swift2