我们正试图以编程方式为iOS 7制作UICollectionView
但是,我们遇到问题,要让细胞显示出来。这是我们的代码。我们知道集合已经完成,numberOfSectionsInCollectionView
被调用,numberOfItemsInSection
被调用。但是cellForItemAtIndexPath
没有或sizeForItemAtIndexPath
。
我们在这里缺少什么?
- (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
*/