Reputation: 1213
I have a UICollectionView
which holds seven UICollectionViewCells
which are build with information coming from a plist file. When I start the App only four UICollectionViewCells
are visible, until i start scrolling down - this makes the violett UICollectionViewCell
visible (see in Screenshot). My question is, how I can display the fourth (violett) UICollectionViewCell
on app start.
In - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
I am building and setting up the cells:
CategoryCollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:catCellID forIndexPath:indexPath];
NSString *plist = [[NSBundle mainBundle] pathForResource:@"mainCategories" ofType:@"plist"];
NSArray *plistArray = [NSArray arrayWithContentsOfFile:plist];
NSDictionary *cat = [plistArray objectAtIndex:indexPath.item];
CGFloat red = [[cat objectForKey:@"color_red"] doubleValue];
CGFloat green = [[cat objectForKey:@"color_green"] doubleValue];
CGFloat blue = [[cat objectForKey:@"color_blue"] doubleValue];
CGFloat alpha = [[cat objectForKey:@"color_alpha"] doubleValue];
UIColor *color = [UIColor colorWithRed:(red/255.0) green:(green/255.0) blue:(blue/255.0) alpha:1];
[cell setBackgroundColor:color];
cell.label_CategoryName = [cat objectForKey:@"text"];
cell.image_CategoryIcon.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.%@",[cat objectForKey:@"image"], kImageExt]];
return cell;
Thank you!
Upvotes: 0
Views: 529
Reputation:
Move the content insets of the collection view downwards incrementally, 1 point at a time, until it starts behaving the way you want it to.
[_collectionView setContentInset:UIEdgeInsetsMake(0, 10, 0, 0)];
CellForRowAtIndex is fired many times and the following code...
NSString *plist = [[NSBundle mainBundle] pathForResource:@"mainCategories" ofType:@"plist"];
NSArray *plistArray = [NSArray arrayWithContentsOfFile:plist];
NSDictionary *cat = [plistArray objectAtIndex:indexPath.item];
Is building an entire new instance of your array in memory, each time. This is very inefficient. Considering instantiating your array once, maybe lazily in a property or in viewDidLoad.
Upvotes: 2