0
在我正在进行的项目中,已经有一个自定义的UITableViewCell,并且我确定问题在于单元的重用。自定义UITableViewCell重复使用突出问题
这2种方法都做了高亮的首要和选择:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
if (self.isCellEditing == NO) {
if (highlighted) {
self.customView.backgroundColor = [UIColor redColor];
} else {
self.customView.backgroundColor = [UIColor whiteColor];
}
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if (self.isCellEditing == NO) {
if (selected) {
self.customView.backgroundColor = [UIColor redColor];
} else {
self.customView.backgroundColor = [UIColor whiteColor];
}
} else {
if (selected) {
self.editImageView.image = self.editAccessorySelectedImage;
} else {
self.editImageView.image = self.editAccessoryImage;
}
}
}
正在发生的事情,是造成这一问题的应用程序是,我需要自动滚动和选择前的最后选定单元格应用程序在应用程序启动时关闭(在viewDidAppear中完成)。这样做除了突出显示单元格之外,实际上它会滚动到单元格中选择它,如细节视图(iPad splitview设置)中所示),但单元格不会突出显示。这是一个重复使用的问题,因为如果需要滚动的单元格是加载时可见的第一个单元格中的一个,它将突出显示,但是如果它是不在屏幕上的单元格,并且滚动到该单元格,它将选择但不突出显示它。
ETA:单元复用覆盖:
- (void)prepareForReuse {
[super prepareForReuse];
self.selectionStyle = UITableViewCellSelectionStyleNone;
_cellEditing = NO;
_swipingToDelete = NO;
_editViewAnimated = NO;
}
单元格的prepareForReuse方法是否被覆盖? – chandu
是的,加在上面。 –
是不是isCellEditing您的自定义属性?不应该在prepareForReuse中重置? – chandu