I'm trying to use RFQuiltLayout
with my UICollectionView
.
I have the CollectionView working fine with the standard UICollectionViewFlowLayout
but it's just a grid. I want my photos to layout nicely as shown here.
I'm having some trouble understanding what's required to use a custom layout with my UICollectionView.
I'm doing everything programatically. I'm not using any Interface Builder/NIBs/Storyboards.
Getting the UICollectionView to layout with the standard FlowLayout was easy, but when I tried to change to the RFQuiltLayout I ran into the following error:
'UICollectionView must be initialized with a non-nil layout parameter'
This seems to be a common error, but none of the suggestions/answers on the other questions helped me resolve it.
So here's the relevant portions of my code:
.h
@interface PFRootViewController : UIViewController <OFFlickrAPIRequestDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (strong, nonatomic) UICollectionView *collectionView;
.m
//UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
//Used to use the above standard FlowLayout, but now trying to move to the below RFQuiltLayout
RFQuiltLayout* layout = (id)[self.collectionView collectionViewLayout];
layout.direction = UICollectionViewScrollDirectionVertical;
layout.blockPixels = CGSizeMake(100, 40);
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) collectionViewLayout:layout];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[PFUICollectionViewCell class] forCellWithReuseIdentifier:@"FlickrCell"];
//Only Layout delegate method i've implemented:
- (CGSize) blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row % 2 == 0)
return CGSizeMake(80, 40);
return CGSizeMake(40, 80);
}
I really don't know what else I've got to do to get this working. If I simply remove the RFQuiltLayout references and uncomment my UICollectionViewFlowLayout alloc init everything works, albeit with the standard FlowLayout.
So if anyone can help point me in the right direction that would be great, this should be simple but it's been a real pain to try and get working. - UICollectionViews aren't as simple as UITableViews.
I spent a good portion of the day yesterday trying to get various custom layouts for my UICollectionView working (including RFQuiltLayout) without any success.
Any help is greatly appreciated,
Regards, John