Reputation: 396
So I have been have some issues with UICollectionView which seems to be a common theme on the internet. Here, Here and Here. I have tried the links suggestions. So just some context.
1.) I'm pulling data from Parse.com (no issue there)
2.) The results are looped over and populated in an array to then fill out the cell. (just like a UITableView)
3.) The data is text based only and populates accordingly, no images to deal with at the moment ;-).
The issue seems to be when I render the dataset. I have set the line spacing between each row to be the following;
//reduce each section to 1px so that it looks like a record set.
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 1.0;
}
//reduce each section to 1px so that it looks like a record set.
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 1.0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *) collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
//UIEdgeInsetsMake(top, left, bottom, right);
return UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
}
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{
return YES;
}
This works accordingly. AFTER you scroll (see below screenshots)
Wrong Render
Correct Render
Cell Code
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"cell";
PatternCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
PFObject *cellObject = [flightRecordData objectAtIndex:indexPath.row];
/* ALL THE UILABEL ELEMENTS ARE SET HERE JUST REMOVED TO SAVE SPACE */
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
[cell.layer setNeedsDisplay];
return cell;
}
I'm happy to deal with the rendering issue because apart from that it works. However, my OCD is kicking in and its doing my head in trying to work out what the issue is. I have even deployed to the device to see if its a simulator issue which its not. Each of the suggested posts from others I have tried but didn't seem to work.
Any ideas on how to fix this? I'm new to iOS so be gentle :-P.
UPDATE: Thanks for the feedback, below is the class and screen shots of the storyboard. I'm using the custom class just as an object that I call when required.
Custom UICollectionViewCell Class
@interface PatternCollectionViewCell : UICollectionViewCell {
IBOutlet UILabel *pilotNameLabel;
IBOutlet UILabel *pilotTotalHoursLabel;
//etc etc...
}
@property (nonatomic,strong) IBOutlet UILabel *pilotNameLabel;
@property (nonatomic,strong) IBOutlet UILabel *pilotTotalHoursLabel;
Storyboard
CollectionView
CollectionViewCell
CustomCell
Upvotes: 0
Views: 1023
Reputation: 17720
You had a mismatch between the item size given in the flow layout (configured on the collection view in Interface Builder), which gave the height as 58 pixels high, and the size of the custom cell, which had a height of only 52 pixels.
This explains the extra spacing around the cell.
Upvotes: 2