Cell of UICollectionView not always refreshed after a scroll

允我心安 提交于 2019-12-03 11:51:57

This seems to be a bug in UICollectionView when using sectionInsets. The cells don't get invisible, they are misplaced out of bounds sometimes on fast scrolling.

So if you normally would have 3 items per row, you will get a forth item in one row, but no item at the first spot of the next row.

If you set your UICollectionView to not clip to bounds, and move it on top of your UI, you might see this misaligned cell.

My solution was so far to not use sectionInsets, and surround it by using contentInset and some empty space in the section headers.

I also found some other guys at Twitter with the same problem. There's also a bug report about it: 12353513

I've had a similar issue. I fixed it by forcing a repaint when setFrame: is called on my custom content. In your case, subclass CPTGraphHostingView and override this method:

-(void)setFrame:(CGRect)frame {
    [super setFrame:frame];
    [self setNeedsDisplay]; // force drawRect:
}

Edit: An easier way to refresh cell views when they are reused is to override applyLayoutAttributes: in iPadCellCollectionViewCell as follows:

-(void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    // apply custom attributes...
    [self.hostingView setNeedsDisplay]; // force drawRect:
}

Regarding your workaround: there will be more and more subviews in the content view, which probably isn't a good thing. However, if you'd remove any old subview before adding the new one, that should be OK, too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!