The Problem
I have an app with a single UICollectionView
that's stuttering the first time that I scroll it. I've narrowed the source down to the fact that new cells (2) are being created (using initWithFrame:
) because there are no cells lying around to be reused. After that initial scroll, the reuse queue isn't empty and cells can be reused and there's no stuttering.
The Hack
So I've been able to workaround the problem with help of a private method in the iOS runtime headers:
- (void)_reuseCell:(id)arg1;
My assumption is that this is where cells are being added back into the reuse queue. The hack to use this undocumented method looks like this:
int prefillCellCount = 10;
NSMutableArray *cells = [[NSMutableArray alloc] initWithCapacity:prefillCellCount];
for (int i=0; i<10prefillCellCount i++) {
UICollectionViewCell *cell = [self.gridView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
[cells addObject:cell];
}
for (UICollectionViewCell *cell in cells) {
[self.gridView _reuseCell:cell];
}
The hack works! There's no stuttering when scrolling.
The Question
I don't think I'll be able to get past the App Store reviewers with this hack. Is there a way to do this without the use of undocumented methods? If not, is my only resort just to obfuscate the hack?