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

时间:2015-02-03 11:43:26

标签: ios objective-c iphone uitableview ios7

我的问题类似于this问题。 我的UITableViewCell Height完美地致力于IOS8。问题IOS7 hight增加但内容未显示。

我的代码是:

- (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无法正常工作

1 个答案:

答案 0 :(得分:1)

使用boundingRectWithSize: NSString公共方法,根据字符串值计算大小。

实施例

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

注意: sizeWithFont:在iOS 7.0中不推荐使用

相关问题