【发布时间】:2018-02-10 03:03:41
【问题描述】:
我需要 UITableViewCell 的动态高度取决于内容长度。
这是一个原型细胞
第一次加载时内容显示正常
但是当我滚动 UITableView 时,单元格的内容会像这样中断,尤其是 UIImageView。
在cell的实现中,我只使用了setImage和setText方法。
似乎有什么问题?或者,在viewDidLoad 之后是否有另一种方法可以不同地设置每个单元格的高度?
** 编辑:这是我对cellForRowAtIndexPath的实现
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NotificationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"notification"];
if(!cell) {
[tableView registerNib:[UINib nibWithNibName:@"NotificationCell" bundle:nil] forCellReuseIdentifier:@"notification"];
cell = [tableView dequeueReusableCellWithIdentifier:@"notification"];
}
[cell setContent:[notifications objectAtIndex:indexPath.row]];
[cell layoutIfNeeded];
return cell;
}
NotificationCell.m 中的setContent 只有setText 和setImage
【问题讨论】:
-
正确配置了动态高度步长???
-
将 [cell layoutIfNeeded] 放在返回单元之前
-
能否显示单元格文件,以及tableView cellForRowAtIndex 路径方法?
-
@iamirzhan 我编辑了帖子,但我认为我做得很好。
-
@AlfredWoo 是的,谢谢!这可能是愚蠢的建议,但是您是否为您的 imageView 创建了出口?因为 UITableView 已经有了 imageView 属性,而且看起来你将图像设置为那个 imageView,因为它在单元格的左侧。
标签: ios uitableview autolayout