在一个UITableViewCell无法改变一个UILabel的第一帧时出现(使用自动布局) [英] Cannot change frame of a UILabel in a UITableViewCell when first appearing (using Autolayout)

查看:122
本文介绍了在一个UITableViewCell无法改变一个UILabel的第一帧时出现(使用自动布局)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我里面有一个原型细胞我的的UITableView 包含一个的UILabel 。我想根据在标签的文本的大小,以动态地改变标签(和该单元)的大小。

I have a prototype cell inside my UITableView which contains a UILabel. I want to dynamically change the size of the label (and the cell) depending on the size of the text in the label.

我创建这样的的cellForRowAtIndexPath 原型细胞:

I create the prototype cell in cellForRowAtIndexPath like this:

static NSString *CellIdentifier = @"ProgramDetailCell";
ProgramDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.descriptionLabel.text = self.program.subtitle;
return cell;

然后我的 ProgramDetailCell 具有以下实现:

@implementation ProgramDetailCell
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.descriptionLabel sizeToFit];
}
@end

显示单元格中的第一次, layoutSubviews 被调用,但 descriptionLabel 没有得到调整。但是,如果我向下滚动表,并再次备份时,重复使用单元格显示带有标签正确调整!

The first time the cell is displayed, layoutSubviews is called, but the descriptionLabel does not get resized. However, if I scroll down the table and back up again, the "reused" cell appears with the label correctly resized!

为什么它不工作的第一次显示细胞 - 什么,我需要做什么来解决它。

Why does it not work the first time the cell is displayed - and what do I need to do to fix it.

在此先感谢!

推荐答案

在厦门国际银行,转到第一个选项卡,在界面生成器文件,取消使用自动布局框。

In xib, go to first tab, under Interface Builder Document , uncheck use Auto Layout box.

这篇关于在一个UITableViewCell无法改变一个UILabel的第一帧时出现(使用自动布局)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆