我正在继承 UITableViewCell。在我的自定义单元格的 xib 中,我有一个 UIImageView,它的框架为 (0, 0, 57, 57)。它的自动布局约束设置为顶部、左侧、宽度和高度。
首次渲染表格 View 时,所有单元格看起来都很好。但是当我滚动时(并因此重用单元格), UIImageView 的框架将变为(15、0、57、57)。其他 subview 似乎都没有受到影响。
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;
}
最佳答案
是自定义单元格吧?如果您为自定义图像或标签使用与默认单元格中相同的属性名称(即 imageView
、 textLabel
或 detailTextLabel
),可能会发生奇怪的事情。尝试重命名 imageView
到别的东西,看看是否能解决它。
关于ios - 重用 UITableViewCell 移动 subview 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19845726/