gpt4 book ai didi

ios - UIViewTableCell 中的布局 subview 不起作用

转载 作者:可可西里 更新时间:2023-11-01 05:54:59 25 4
gpt4 key购买 nike

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

我需要调整单元格中一些标签的大小,所以我在

中调用了以下方法
- (void)layoutSubviews {
[super layoutSubviews];
[_titleLabel sizeToFit];
}

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

enter image description here

但是在我点击这个单元格并选择它之后,标题确实调整了大小:

enter image description here

加载数据的代码如下:

- (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 会根据您在 Interface Build 中制作标签时设置的约束再次为您调整标签的大小,不幸的是在 autolayout 下层次结构是约束> 框架

关于ios - UIViewTableCell 中的布局 subview 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19834718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com