如何为UITableViewCell获取动态高度

时间:2016-01-28 07:11:35

标签: ios uitableview uiview

我创建了Customized tableViewCell,我在UITableViewCell中添加了UIView SubView。所以我的动态文字& UIView中的图像内容,它将根据文本和图像大小而变化。  但是现在在HeightforRowAtIndex中得到错误,这里我直接返回了UIView frame.size.height + 10;它在iOS8.1中运行良好,但它不能在所有版本下工作。

下面添加了一段代码&与图像。

import java.util.Scanner;

public class EnumExample {
    public enum Alphabets {
        A, B, C, D
    }

    public static void main(String[] args) {
        Scanner keyboardInput = new Scanner(System.in);
        System.out.println(Alphabets.A);
    }
}

这里_cellbackground视图,高度将根据文本和图像内容动态变化。

public static boolean isGameOver(int score, int lives, int level) {
    while(lives > 0){
        switch (level) {
        case 1:
            return (score > 1000) ? false : true ;

        case 2:
            return (score > 2000) ? false : true ;

        case 3:
            return (score > 3000) ? false : true ;
        }
    return false;
    }
}

这里我根据UIView高度返回高度,但它只适用于(iPhone 6s)iOS8.1。但其他人则无法正常工作。 请建议我从iPhone 5(7.1)获取高度enter image description here此图像的最佳方法,它将无法正常工作。

enter image description here它来自iPhone 6(8.1)正常工作。

请指导我返回身高的最佳解决方案。(HeightForRowAtIndex)。

1 个答案:

答案 0 :(得分:0)

表示在viewDidLoad中设置的UITableViewCell的动态高度

_tableView.estimatedRowHeight = 100.0;
_tableView.rowHeight = UITableViewAutomaticDimension;

根据内容高度设置自动单元格高度

让我知道这是否有效......