Reputation: 3681
I have a collection view with like 7-8 different cells. Cells are constructed in XIB files. Then in View Controller I use:
[self.collectionView registerNib:[UINib nibWithNibName:name bundle:nil] forCellWithReuseIdentifier:name];
Everything works as expected, but there are some performance issues. On the first scroll collection view noticeably lags as cells appear. After all kind of cells have been loaded at least once everything starts to scroll smoothly. Cells are not really complicated.
Q: Why do you even use XIBs for that, why not prototype cells in a storyboard?
A: Same cells are used in different collection views throughout the app. This way I can apply changes to a cell once in a xib. I couldn't come up with easier solution to do that.
I'm pretty sure UINib is cached after it's loaded and this is why it stops lagging. I was wondering if there's a way to preload those xibs at the splash screen for example. It will take a second or two, but will result in smoother experience.
Upvotes: 1
Views: 262
Reputation: 26383
UINib
are cached once loaded, there are plenty of reason that could make scrolling laggy:
cornerRadius
on a layer
?Using instruments you can really check most of those issues, for instance Time Profiler
will help you in checking if something is blocking the UI, using simulator you can activate Color Blended Layer to search for transparencies (in red) and Color Offscreens render to check for offscreen render views (in yellow)
Upvotes: 0