UICollectionViewCell reuse issue

404 views Asked by At

I have a storyboard and one of my viewControllers has a CollectionView. I have a prototype cell that has a label inside. I created a class for that prototype cell in order to have access to the label via an IBOutlet property.

The problem is that I have many cells. Inside the initWithCoder constructor of the cell I add some cornerRadius.

When I push this viewController on the screen, it lags a lot. Without the corner radius it doesn't. I also noticed that initWithCoder gets called all the time, for each cell.

I tried to register the cell like this [self.myCollectionView registerClass:[MyCell class] forReuseIdentifier:@"MyReuseIdentifier"] but it doesn't work. I dont know how to use the registerNib method.

The reuse identifier is set in the storyboard prototype cell.

I don't know how to achieve the rounded corner effect without loss in perforrmance.

1

There are 1 answers

1
Retro On

I have done my cell corner round in cellForItemAtIndexPath method like

    cell.imageView.layer.cornerRadius = 10;
    cell.imageView.layer.masksToBounds = YES;

and dont forget to import #import <QuartzCore/QuartzCore.h>