Han*_*nXu 5 label position objective-c ios
我有一个类PostListTableCell,它继承了UITableViewCell,它用作UITableView中的自定义单元格。
我需要调整单元格中某些标签的大小,因此我在
- (void)layoutSubviews {
[super layoutSubviews];
[_titleLabel sizeToFit];
}
Run Code Online (Sandbox Code Playgroud)
但是问题是,当加载UITableView时,_titleLabel不会调整大小:

但是,当我单击此单元格并选择它后,标题的大小确实调整了:

以下是加载数据的代码:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
| 归档时间: |
|
| 查看次数: |
2701 次 |
| 最近记录: |