【问题标题】:UITableview Cell height not working in IOS7UITableview单元格高度在IOS7中不起作用
【发布时间】:2015-04-02 14:23:15
【问题描述】:

我的问题类似于this SO question。 我的UITableViewCell Height 完美地工作在IOS8IOS7 的问题是高度增加但内容不显示。

我的代码是:

- (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不工作

【问题讨论】:

  • 您使用的是故事板和自动布局?
  • 没有。我正在使用 xib 并且自动布局已关闭
  • 如果 (hightmain
  • 我不确定这是否与您的问题有关,但 sizeWithFont:constrainedToSize:lineBreakMode: 自 iOS7 以来已弃用,请小心
  • 选择行时是否重新加载 tableView?heightForRowAtIndexPath 仅在填充表格或滚动表格时调用。

标签: ios objective-c iphone uitableview ios7


【解决方案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 中已弃用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    相关资源
    最近更新 更多