ios - UITableview 单元格高度在 IOS7 中不起作用

标签 ios objective-c iphone uitableview ios7

我的问题类似于this所以问题。 我的 UITableViewCell HeightIOS8 上完美工作。 IOS7 问题高度增加但内容不显示。

我的代码是:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
long hightmain=0;

    if(selectIndex && indexPath.section == selectIndex.section)
    {

        NSString * myString = [description_vegetable_array objectAtIndex:indexPath.section];
        CGSize labelSize = [myString sizeWithFont:[UIFont systemFontOfSize:15]  constrainedToSize:CGSizeMake(190, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
        hightmain=labelSize.height+120;

        if (hightmain<=140)
        {
             btn11.frame=CGRectMake(240,100,70,17);
             Description_LBL.frame=CGRectMake(127, 0, 190, 140);
             BGImage.frame=CGRectMake(0, -3, 320, 140);
        }
        else
        {                               
            [btn11 setTitle:@"Less Info" forState:UIControlStateNormal];
            btn11.frame=CGRectMake(240,hightmain-30,70,17);
            Description_LBL.frame=CGRectMake(127, -20, 190, hightmain);
            BGImage.frame=CGRectMake(0, -3, 320, hightmain);
            return hightmain;
        }
    }
    else
    {
        return 140;
    }
}

Description_LBL.frame=CGRectMake(127, 0, 190, 140); 我的标签高度增加但文本不显示....在 IOS8 中完全工作但 IOS7 不工作

最佳答案

使用 boundingRectWithSize: which NSString public methods that calculates the size based on a string value.

例子

[testString boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil]

注意: sizeWithFont:在 iOS 7.0 中已弃用

关于ios - UITableview 单元格高度在 IOS7 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28298076/

相关文章:

iphone - 应用程序 ID 不同形式的 Bundle ID?

iphone - 设置 hidesBottomBarWhenPushed 会在弹出 View Controller 后导致底部栏丢失

iphone - Objective-C 的内置 rand() 函数的确切算法是什么?

ios - iPhone 中方法调用的 CPU 和内存使用情况

ios - 如何链接到 Storyboard Xcode 的另一个 View

ios - 从另一个应用程序打开设置应用程序

ios - 在 iOS 6.1 中工作的 UIPickerView 现在在 Xcode 5 中崩溃

iphone - 在 iPhone 上重新创建日历 "Day" View ?

ios - 当用户从照片库中选择一张时图像会旋转

html - 在 WKWebView 中加载单个 HTML 元素