我剛開始第一次使用UICollectionView玩耍。似乎很好地工作,但有一個問題和一個問題。UICollectionView registerCell - 空白單元格
我有如下我UICollectionView設置和使用自定義單元格:
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
return 10;
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ContactCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
cell.nameLbl.text = @"text";
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(145, 95);
}
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(10, 10, 10, 10);
}
因此,這是所有的花花公子,但我已經加入這一行到viewDidLoad
:
[collectionView registerClass:[ContactCell class] forCellWithReuseIdentifier:@"Cell"];
這是造成麻煩我不明白爲什麼。當我啓用此行時,我的所有單元格都變爲空白。怎麼來的?我錯過了什麼?
另外,據我所知,如果該行啓用可重用的單元格,爲什麼我必須使用集合視圖vs不必在表視圖中?
任何技術或解釋性幫助表示感謝, 謝謝。
你怎麼設置單元格的看法?以編程方式在你的子類? – jackslash
我在Storyboard中設置了它。我有一個UICollectionView與單個單元格,該單元格的標識符,自定義類掛鉤並在其中標記。 –