ios - 重用 UITableViewCell 移动 subview 框架

标签 ios objective-c uitableview

我正在继承 UITableViewCell。在我的自定义单元格的 xib 中,我有一个 UIImageView,它的框架为 (0, 0, 57, 57)。它的自动布局约束设置为顶部、左侧、宽度和高度。

首次渲染表格 View 时,所有单元格看起来都很好。但是当我滚动时(并因此重用单元格), UIImageView 的框架将变为(15、0、57、57)。其他 subview 似乎都没有受到影响。

enter image description here

UITableView 数据源:

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    Content* content = [[[ContentManager sharedContentManager] allContent] objectAtIndex:indexPath.row];
    ContnetCell* cell = [tableView dequeueReusableCellWithIdentifier:kCellReuseIdentifier forIndexPath:indexPath];
    [cell loadWithContent:content];
    return cell;
}

细胞:
{
    [super prepareForReuse];
    self.imageView.image = nil;
}

-(void)loadWithContent:(Content*)content
{
    self.imageView.image = content.contentImage;
}

最佳答案

是自定义单元格吧?如果您为自定义图像或标签使用与默认单元格中相同的属性名称(即 imageViewtextLabeldetailTextLabel ),可能会发生奇怪的事情。尝试重命名 imageView到别的东西,看看是否能解决它。

关于ios - 重用 UITableViewCell 移动 subview 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19845726/

相关文章:

iOS Cocoapods 问题 : No such module in parts of my project (custom folder & Apple Watch target)

ios - 带有导航 Controller 的不同页面上的 Xamarin.SideBar

ios - 如何将 iCarousel autoScrollDirection 从左到右更改为从右到左

ios - UICollectionView 的框架未正确更新为 UITableViewCell subview

ios - 在字符串中查找数字并计算,插入字符串中(Swift)

ios - Mapbox - 计算 MGLPointAnnotation 是否在 MGLPolygon 内

iphone - "UIWindowLevelStatusBar + 1"奇怪的键盘行为

objective-c - 保留和复制之间的区别?

ios - 在ios中从UITableView、Plist生成PDF

UITableView 设置网页 View 和网页 View 外的按钮作为背景