【发布时间】:2013-04-18 01:12:47
【问题描述】:
正如标题所示,我有一个 UICollectionView,它通过 IB 连接到 UIViewController。我有一个名为imageCell 的UICollectionView 子类。在 viewcontroller viewDidLoad 方法中,我这样注册类:
CGRect collectionViewRect = CGRectMake(384, 60, 728, 924);
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
imageCollectionView = [[UICollectionView alloc] initWithFrame:collectionViewRect collectionViewLayout:flow];
[imageCollectionView registerClass:[imageCell class] forCellWithReuseIdentifier:@"Cell"];
imageCollectionView.delegate = self;
imageCollectionView.dataSource = self;
然后我在 viewDidAppear 中调用一个名为 getPhotos 的方法(出于 UI 原因),该方法从服务中获取照片,然后我在 getPhotos 中调用 [imagCcollectionView reloadData];。
然后在cellForItemAtIndexPath 我执行以下操作:
imageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
GRKAlbum *album = [albums objectAtIndex:indexPath.item];
cell.titleLabel.text = album.name;
return cell;
我知道我在这里没有做错任何事情,因为正在调用该方法并且cell 不是nil,album 也不是。
所以,当我运行所有这些代码时,UICollectionView 出现了,但里面什么都没有。我只能看到collectionView 的背景颜色。任何帮助都将不胜感激。
注意:当我创建 imageCell 类时,我并没有为它创建 XIB,而是使用 Storyboards。
【问题讨论】:
标签: ios uicollectionview uicollectionviewcell