Swift: 一个 UICollectionViewCell 的不同 xibs 布局

Swift: different xibs layouts for one UICollectionViewCell

是否可以为一个 UICollectionViewCell 使用多个 xib 布局。假设我有一个只有文本字段的 xib 布局,我们称它为 "textfield.xib" 和一个只有图像的 xib,"image.xib"。在 collectionViewDelegate 函数 cellForItemAtIndexPath 中,我声明了两个单元格,如下代码所示:

cell:ImageCell=collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as ImageCell
cell:TextFieldCell=collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as TextFieldCell

现在的问题是如何注册nibs。据我所知,我只能为一个 collectionView 注册一个笔尖。

您的假设不正确;您可以根据需要注册任意数量的单元格。但是,您应该在注册时以及在 cellForItemAtIndexPath 中为它们提供不同的标识符。