细胞高度没有动态改变ios 7

时间:2015-01-09 08:04:45

标签: ios uitableview autolayout

我已经按照本教程了解动态单元格高度: http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout

我的代码如下:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ChatViewCell *cell=(ChatViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ChatViewCell"];
    if (cell==nil) {
        for (id currentObject in [[NSBundle mainBundle] loadNibNamed:@"ChatViewCell" owner:self options:nil]) {
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                cell = (ChatViewCell *)currentObject;
                break;
            }
        }
    }
    cell.IBlblDate.text = @"8 th jan,2015";
    if (indexPath.row==0) {
    cell.IBlblMsg.text = @"HelloHelloHelloHelloHello";
    }
    if (indexPath.row==2) {
        cell.IBlblMsg.text = @"HelloHelloHelloHelloHelloHelloHelloHelloHelloHello";
    }
    if (indexPath.row==1) {
        cell.IBlblMsg.text = @"HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello";
    }
    if (indexPath.row==3) {
        cell.IBlblMsg.text = @"HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello";
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 49;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    ChatViewCell *cell = (ChatViewCell *)[IBtblView cellForRowAtIndexPath:indexPath];

    [cell setNeedsLayout];

    [cell layoutIfNeeded];


    CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    return size.height + 1.0f;
}

但我得到的输出如下:

enter image description here 请帮我解决这个问题。

0 个答案:

没有答案