OGeek|极客世界-中国程序员成长平台

标题: ios - 滚动时自定义单元格图像变形 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:57
标题: ios - 滚动时自定义单元格图像变形

我的 UITableView 有一个自定义单元格;该自定义单元格来自扩展 UITableViewCell 的类。 只有一个 .xib 我在其中创建了实际的单元格,以及 .h 中这些项目的链接。 我没有使用 .m,它只是其中的自动生成的 awakeFromNibsetSelected:selected:animated

当我在 cellForRow 方法中创建我的单元格时,一切都很好,它正确显示在屏幕上。

-(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"CustomCellTableViewCell";
    CustomCellTableViewCell *cell = [self.tbUpcomingEvents dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    tmp = [_eventList objectAtIndex:indexPath.row];

    cell.lbDescription.text = tmp.description;
    cell.lbTitle.text = tmp.title;

    cell.imageView.layer.cornerRadius = 20;
    cell.imageView.clipsToBounds = YES;
    cell.layer.masksToBounds = YES;
    cell.imageView.image = [UIImage imageNamed:tmp.type.typeImage];

    cell.lbTimeStart.text = [[[timeFormatter stringFromDate:tmp.startTime] stringByAppendingString" - "]stringByAppendingString:[dateFormatter stringFromDate:tmp.startDate]];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

我的问题如下:当我开始滚动表格 View 时,新单元格被搞砸了,特别是图像。它只是变得更大/更宽并且(显然)变形。我真的不知道是什么原因造成的,也不知道如何解决。

单元格与来自 cellForRow 方法的重用标识符和 .xib 文件中的自定义类相关联。 UITableView 没有什么特别的(除了 Storyboard -> .h、delegate、datasource 之外没有其他链接)

有什么线索吗?



Best Answer-推荐答案


我发现了我的问题。在这种特定情况下,我的 customCell.h 中的 imageView 被称为“imageView”。这是一个保留的命名,我猜,在创建单元格的(某些?)点上产生了冲突。

我不知道为什么,但我知道是什么解决了这个问题。现在我只是为我的图像添加了另一个属性名称,我是金色的;)

关于ios - 滚动时自定义单元格图像变形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24994116/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4