Cell of UICollectionView not always refreshed after a scroll

前端 未结 2 1507
囚心锁ツ
囚心锁ツ 2021-02-13 12:06

I have defined in my Storyboard (iPad) a view that contains a UICollectionView, at the bottom of the view there\'s also a UIToolbar. In the UICol

2条回答
  •  有刺的猬
    2021-02-13 12:33

    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.

提交回复
热议问题