简体   繁体   中英

UITableview Cell height not working in IOS7

My problem is similar to this SO question. my UITableViewCell Height perfect working on IOS8 . Problem With IOS7 hight is increase but content is not display.

my code is:

- (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); my label height increases but text not display ....in IOS8 complete working but IOS7 in not working

Use boundingRectWithSize: which NSString public methods that calculate the size based on a string value.

Example

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

Note: sizeWithFont: Deprecated in iOS 7.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM