desc:
i have a view controller that holds a collection view with 7 cells inside of it. when i display this controller, all works fine and it displays perfectly (controller A). on another controller (controller B) i have a container view that embeds controller A, with the collection view.
the problem:
when running the app and going into controller B (that embeds controller A), all controller A's sub views look good except of the collection view. in this case, instead of seeing my 7 cells i see only 6 and after tapping on one of the cells, the last cell appears in the cells row and now it looks good (?!). its like the collection view is being redrawn and i cant find the reason or how to fix it.
any help is appreciated.
Edit
that is my flow layout, which i call from viewDidLoad:
-(void) setFlowLayout {
BOOL isIphone = (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad);
float baseWidth = [[UIScreen mainScreen] bounds].size.width;
int width;
width = floor(baseWidth / 7.0);
float space = baseWidth - (width * 7.0f);
space /= 7.0;
UICollectionViewFlowLayout * flow = [[UICollectionViewFlowLayout alloc] init];
if(isIphone) {
flow.itemSize = CGSizeMake(width, kCellHeight);
}
else{
flow.itemSize = CGSizeMake(width, kCellSizeIpad);
}
flow.minimumInteritemSpacing = space;
flow.headerReferenceSize = CGSizeMake(_collectionDays.frame.size.width, kSpacing);
flow.footerReferenceSize = CGSizeZero;
flow.scrollDirection = UICollectionViewScrollDirectionVertical;
[_collectionDays setCollectionViewLayout:flow];
}
i also use this to place the cells in the middle of the collection view:
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
CGFloat cellSpacing = ((UICollectionViewFlowLayout *) collectionViewLayout).minimumInteritemSpacing;
CGFloat cellWidth = ((UICollectionViewFlowLayout *) collectionViewLayout).itemSize.width;
NSInteger cellCount = [collectionView numberOfItemsInSection:section];
CGFloat inset = (collectionView.bounds.size.width - (cellCount * (cellWidth + cellSpacing))) * 0.5;
inset = MAX(inset, 0.0);
return UIEdgeInsetsMake(0.0, inset, 0.0, inset);
}