Ios UITableViewCell高度在用户滚动之前不调整

Ios UITableViewCell高度在用户滚动之前不调整,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在尝试用文本填充cell.textLabel。该文本在数组中每个对象的行数不同,因此单元格需要调整高度。在用户滚动列表之前,单元格不会调整高度 这里是代码 IB的形象 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCel

我正在尝试用文本填充cell.textLabel。该文本在数组中每个对象的行数不同,因此单元格需要调整高度。在用户滚动列表之前,单元格不会调整高度

这里是代码

IB的形象

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
        cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];


      cell.textLabel.text = [kanyeLines objectAtIndex:indexPath.row];

        return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellText =[kanyeLines objectAtIndex:indexPath.row];
    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];

    NSAttributedString *attributedText =
    [[NSAttributedString alloc]
     initWithString:cellText
     attributes:@
     {
     NSFontAttributeName: cellFont
     }];
    CGRect rect = [attributedText boundingRectWithSize:CGSizeMake(tableView.bounds.size.width, CGFLOAT_MAX)
                                               options:NSStringDrawingUsesLineFragmentOrigin
                                               context:nil];

    return rect.size.height + 20;
}

因此,我无意中为表设置了两次数据源,而没有设置委托

你在用故事板吗?@AshrafTawfeeq是的。我猜你没有实现*heightForRow…`或
estimatedHeightForRow…
。它已经实现了。您可以在上面的代码中看到它。