我有一个包含自定义单元格的表格视图,它覆盖setSelected:animated:
. 有时,当滚动包含选定单元格的表格时,选定单元格的外观是选定和未选定状态的奇怪混合。
我的setSelected:animated:
方法如下所示:
-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
if (selected == self.selected)
return;
CGFloat destinationAlpha = selected ? 1.0 : 0.0;
NSTimeInterval duration = animated ? 0.25 : 0.0;
for (UIView *view in self.topView.subviews)
{
if (![self.viewsToLeaveBackgroundAlone containsObject:view])
view.backgroundColor = [UIColor clearColor];
}
[UIView animateWithDuration:duration animations:^{
self.selectedTopViewBackground.alpha = destinationAlpha;
}animations completion:^(BOOL finished) {
if (!selected)
{
for (UIView *view in self.topView.subviews)
{
if (![self.viewsToLeaveBackgroundAlone containsObject:view])
view.backgroundColor = self.topView.backgroundColor;
}
}
}];
[super setSelected:selected animated:animated];
}
我已经添加了日志和断点,并且正确的单元格正在将正确的选定状态发送给它。可能出了什么问题?