ios - UILabel 在第一次滚动时不会更改 UITableViewCell 中的高度

标签 ios objective-c uitableview

我在 Storyboard上使用 tableview。

我在 (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 函数中更改标签的框架。

然后,经过一些滚动,它可以改变框架。但是,当我打开我的应用程序时,框架一开始并没有改变。

抱歉,只有 10 点声望才能发布图片。 请帮忙。

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
// get one row
Plan* planObj = [_planObjList objectAtIndex:indexPath.row];

// get custom cell info
LargeImageCell* cell = (LargeImageCell*)[tableView dequeueReusableCellWithIdentifier:@"CustomLargeImageCell"];

cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg"]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.titleLabel.text = planObj.planTitle;
cell.titleLabel.numberOfLines = 0;
cell.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.userNameLabel.text = planObj.getProducerName;

// title size
CGSize titleSize = [cell.titleLabel.text boundingRectWithSize:CGSizeMake(300.0f, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: cell.titleLabel.font} context:nil].size;
// user name size
CGSize userNameSize = [cell.userNameLabel.text boundingRectWithSize:CGSizeMake(300.0f, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: cell.userNameLabel.font} context:nil].size;

// set title size
cell.titleLabel.frame = CGRectMake(7.0f, 230.0f, 306.0f, ceilf(5.0f + titleSize.height));
cell.titleLabel.backgroundColor = [UIColor redColor];

// set name size
cell.userNameLabel.frame = CGRectMake(7.0f, ceilf(235.0f + titleSize.height), 148.0f, ceilf(5.0f + userNameSize.height));
cell.userNameLabel.backgroundColor = [UIColor blueColor];
}

最佳答案

自动布局有问题。
我在 Storyboard上关闭了“使用自动布局”。然后,它变得清楚了。

谢谢大家

关于ios - UILabel 在第一次滚动时不会更改 UITableViewCell 中的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20398079/

相关文章:

ios - 检测图像中的边缘

ios - __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ 18 23 CoreFoundation 崩溃

objective-c - 以 Retina 质量屏蔽 2 个 UIImages

ios - 简单的 NSData 类别来解析带有西里尔字母的 XML

objective-c - UITableView 不会显示 headerView.xib

ios - 如何在 Swift 中从 indexPath 获取 UITableViewCell 对象?

objective-c - 从 UITableView 中删除没有行的部分

ios - ScrollView 内的表格 View : expand table view on scrolling and hide view above it

iphone - 创建许多具有不同内容的 ViewController 并在它们之间移动

iOS UITableView 选择隐藏 subview 按钮背景色