【发布时间】:2014-06-11 05:35:57
【问题描述】:
我正在尝试为我正在创建的没有 XIB 文件的 UICollectionView 创建一个带有 XIB 文件的 UICollectionViewCell。
以下是我创建 CollectionView 的方法:
_collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:collectionViewFlowLayout];
[_collectionView setDelegate:self];
[_collectionView setDataSource:self];
[_collectionView setBackgroundColor:[UIColor clearColor]];
[_collectionView registerClass:[CustomCell class] forCellWithReuseIdentifier:carouselItemReuseIdentifier];
[self.view addSubview:_collectionView];
我是这样称呼自定义单元格的:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:carouselItemReuseIdentifier forIndexPath:indexPath];
[cell refreshWithData];
return cell;
}
在 XIB 文件中,我将自定义类设置为 CustomCell - 但是当我加载集合视图时,我只看到矩形 - 而不是我为自定义类创建的 XIB。
【问题讨论】:
标签: objective-c xcode uicollectionview xib uicollectionviewcell