Ios UITableViewCell内的UILabel未展开以显示文本

Ios UITableViewCell内的UILabel未展开以显示文本,ios,objective-c,uitableview,uilabel,Ios,Objective C,Uitableview,Uilabel,我有一个自定义的UITableViewCell,其中包含两个UILabels。一个用于标题,另一个用于摘要。摘要是从web服务返回的,它至少有10行长。我想在UILabel中显示所有这些行 我已将抽象的UILabel设置为0。换行符设置为换行。我甚至在分配抽象文本后调用sizeToFit,如下所示: -(void) configure:(Story *)story { self.titleLabel.text = story.title; self.abstractLabel.

我有一个自定义的
UITableViewCell
,其中包含两个
UILabel
s。一个用于标题,另一个用于摘要。摘要是从web服务返回的,它至少有10行长。我想在
UILabel
中显示所有这些行

我已将抽象的UILabel设置为0。换行符设置为换行。我甚至在分配抽象文本后调用
sizeToFit
,如下所示:

-(void) configure:(Story *)story
{
    self.titleLabel.text = story.title;

    self.abstractLabel.text = story.abstract;

    [self.abstractLabel sizeToFit];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"StoryCell";
    StoryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    Story *story = [_stories objectAtIndex:[indexPath row]];

    [cell configure:story];

    return cell;
}
UITableView
cellForRowIndex
如下所示:

-(void) configure:(Story *)story
{
    self.titleLabel.text = story.title;

    self.abstractLabel.text = story.abstract;

    [self.abstractLabel sizeToFit];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"StoryCell";
    StoryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    Story *story = [_stories objectAtIndex:[indexPath row]];

    [cell configure:story];

    return cell;
}
结果如下所示:

-(void) configure:(Story *)story
{
    self.titleLabel.text = story.title;

    self.abstractLabel.text = story.abstract;

    [self.abstractLabel sizeToFit];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"StoryCell";
    StoryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    Story *story = [_stories objectAtIndex:[indexPath row]];

    [cell configure:story];

    return cell;
}

sizeToFit方法将调整UILabels框架的大小,以适应其superview,在本例中,它是UITableViewCell。相反,您需要使用BoundingRectiveWithSize:加上标题的大小来估计文本的大小,以便以heightForRowAtIndexPath:的形式正确调整UITableViewCell的大小,然后调用UILabel上的sizeToFit。如果您使用的是AutoLayout,那将是另一个故事,我还没有这方面的经验。是的,我使用的是AutoLayout。此外,UILabel上没有约束,因此在调用sizeToFit时,它应该根据文本大小展开。是否设置行高?您是否正在设置单元格的框架高度?原来是自动布局约束。我会在几个小时后发布答案。约翰,如果你还可以发布的话,我可以使用你的答案,我也有同样的问题。