Problem
I have an application with one UICollectionView that stutters the first time I scroll through it. I narrowed down the source to the fact that new cells (2) are created (using initWithFrame: , because there are no cells that can be reused. After this initial scroll, the reuse queue is not empty, and the cells can be reused, and there is no stuttering.
The hack
So, I was able to solve the problem using a private method in iOS runtime headers:
- (void)_reuseCell:(id)arg1;
My guess is that this is where cells are added back to the reuse queue. The hack to use this undocumented method is as follows:
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]; }
Failure is working! There is no stutter when scrolling.
Question
I donβt think I can get past App Store reviewers with this hack. Is there a way to do this without using undocumented methods? If not, is this my only resort to just confuse the hack?
source share