We are trying to make a UICollectionView
for iOS 7 programmatically however, we are running into problems for the cells to show up. Here is our code. We know that the collection gets made and the numberOfSectionsInCollectionView
gets called and the numberOfItemsInSection
gets called. However the cellForItemAtIndexPath
does not or the sizeForItemAtIndexPath
.
What are we missing here?
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setUpCollectionView];
}
return self;
}
- (void) setUpCollectionView
{
collectionViewLayout = [[UICollectionViewLayout alloc] init];
teamCollectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout: collectionViewLayout];
[teamCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier: @"cellIdentifier"];
teamCollectionView.dataSource = self;
teamCollectionView.delegate = self;
teamCollectionView.backgroundColor = [UIColor yellowColor];
[self addSubview: teamCollectionView];
}
/**
* STARTS THE COLLECTION VIEW FOR THE VIEW
*/
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath: indexPath];
cell.backgroundColor = [UIColor greenColor];
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 15;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(50, 50);
}
/**
* ENDS THE COLLECTION VIEW FOR THE VIEW
*/