我有一个自定义的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