UIViewTableCell中的layoutSubviews不起作用 [英] layoutSubviews in UIViewTableCell does not work

查看:138
本文介绍了UIViewTableCell中的layoutSubviews不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类PostListTableCell,它继承了UITableViewCell,它用作我的UITableView中的自定义单元格.

I have a class PostListTableCell, inheriting UITableViewCell, which is used as my custom cell in a UITableView.

我需要调整单元格中某些标签的大小,因此我在

I need to resize some labels in the cell, so I called following method in

- (void)layoutSubviews {
    [super layoutSubviews];
    [_titleLabel sizeToFit];
}

但是问题是,当加载UITableView时,_titleLabel不会调整大小:

But the problem is, when the UITableView loaded, the _titleLabel does not resize:

但是在我单击此单元格并将其选中之后,标题的大小确实发生了调整:

But after I click this cell and select it, the title did resize:

以下是加载数据的代码:

Following is the code to load data:

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

    if (cell == nil) {
        cell = [[PostListTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PostListTableCellIdentifier];
    }

   Post *post = (Post*)_posts[indexPath.row];
    [cell loadPost:post];

    return cell;
}

有人可以帮忙吗?

推荐答案

问题是自动布局,它会根据您在界面中制作标签时设置的约束为您重新调整标签的大小不幸的是,在 autolayout 下进行构建,层次结构为约束> 框架

The problem is the autolayout that resize again the label for you with the constraints that you had set when you make the label in Interface Build, unfortunately in under autolayout the the hierarchy is Constraints > Frame

这篇关于UIViewTableCell中的layoutSubviews不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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