我是 UICollectionView
的新手。
我已关注this tutorial学习如何使用 UICollectionView
,但问题是在 .xib
(不使用 Storyboard)中我无法添加 UICollectionViewCell
作为 UICollectionView
的 subview 。
在本教程中,单元格是在 .xib
中的 UICollectionView
下自动创建的。
如有任何帮助,我们将不胜感激。
最佳答案
该教程适用于在 xib 中的 stroy board 中工作,您必须首先创建自定义单元格创建 View Controller 添加 UicollectionView 来查看 Controller
然后为集合单元格创建自定义类
然后创建空的 xib 资源并添加 Collection View 单元格
并设置该控件的类名和标识符
然后创建委托(delegate)方法将自定义单元添加到您的 collectionViewController
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"customCell";
customCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
return cell;
}
关于ios - UICollectionView 单元格未添加为 UICollectionView 的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20994378/