【问题标题】:UITableViewCell Custom HeightUITableViewCell 自定义高度
【发布时间】: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


    【解决方案1】:

    当然这不是一个很好而明确的答案,但设置自动布局可能存在问题。通常很难在此处提供带有布局和约束的所有数据,因此您最好检查一些材料,例如this。然后检查你的代码。

    【讨论】:

      【解决方案2】:

      我认为记分牌布局设置有问题,请按照 link 和link 检查设置单元格

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-25
        • 2018-07-06
        • 2015-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多