我试图基本复制本教程
https://www.youtube.com/watch?v=i9eFo2fRCdU
进入一个现有的项目,但它的视图控制器继承自UICollecitonview,因为我现有的项目是从UIViewController继承的,有没有办法解决这个问题呢?这是我试图开始工作的代码:
- (UICollectionViewCell*) collectionView:(UICollectionViewCell *)
collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Cell * aCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];
aCell.myLabel .text = self.dataArray[indexPath.row];
return aCell;
}
答案 0 :(得分:0)
您可以在您选择的视图控制器中使用UICollectionView。有必要分配/ init:
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10.0f, 100.0f, 525.0f, 500.0f) collectionViewLayout:flowLayout];
[collectionView setDelegate:self];
[collectionView setDataSource:self];
[collectionView setAllowsMultipleSelection:NO];
[collectionView setAllowsSelection:NO];
[collectionView setBackgroundColor: [UIColor whiteColor]];
[collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
[self.view addSubview:collectionView];
然后,您需要实现通常的委托/数据源方法。像上面那样。