我有一個自定義的TagCollectionViewCell,它是一個自定義的UICollectionViewCell。在.xib的日子裏,我曾經通過UINib實例化,但現在使用Storyboard我很無聊。CollectionViewCell問題。從.xib到自定義collectionviewcell的故事板轉換
\t UINib *cellNib = [UINib nibWithNibName:@"TagCollectionViewCell" bundle:nil];
\t [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"TagCell"];
\t
\t
\t _sizingCell = [[cellNib instantiateWithOwner:nil options:nil] objectAtIndex:0];
在故事板貼我的筆尖在.storyboard,給它分配的自定義類。但我得到一個白色的屏幕。這是我的自定義收集單元,我希望它成爲故事板。
我應該在集合視圖cell_for_item_atindexpath中做什麼更改。 .xib的代碼如下。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
\t TagCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TagCell" forIndexPath:indexPath];
\t
\t [self _configureCell:cell forIndexPath:indexPath];
\t
\t return cell;
}
和配置佈局是這樣的。
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
\t [self _configureCell:_sizingCell forIndexPath:indexPath];
\t
\t return [_sizingCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
}
嗨。看到我的回答如下 – LearneriOS