【发布时间】:2014-01-17 21:30:55
【问题描述】:
我想要实现的是一个带有UICollectionView 的 3x3 表。但它只是在运行应用程序时不显示任何单元格。它确实显示了CollectionView 的背景颜色(我设置为蓝色)有人可以帮我吗?
我所做的是创建一个storyboard 并简单地将CollectionViewController 拖到它上面。这个控制器还带来了一个嵌套的CollectionView。然后我简单地使用设置将其背景设为蓝色并添加一个单元格,我将背景设为紫色(两者都仅用于测试)。最后将UILabel 拖到上面。现在运行时它只显示蓝色背景,但没有单元格,即使它们在编辑器中清晰可见。然后我尝试创建一个自定义UICollectionViewController,将类分配给CollectionViewController 而不是标准类,并对单元格执行相同操作(分配一个自定义UICollectionViewCell)。在自定义UICollectionViewController中我实现了以下方法:
-(NSIntegear)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 9;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
AboutYourGoalsMultiSelectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
[[cell goal]setText:@"T"];
return cell;
}
我将单元格的标识符设置为“Cell”,并在 CollectionView 和自定义 UICollectionViewController 之间建立了 dataSource 和委托的出口连接。一切都编译得很好。 那么我错过了什么?在简单地使用编辑器进行所有这些调整之前,它不应该显示一些东西吗?
【问题讨论】:
-
CollectionViewCell 的单元格标识符是否设置为“Cell”?
-
是的,Collection Reusable View > Identifier 设置为“Cell”并且 Identity > Restoration ID 也是
-
什么都没有。我会在
collectionView:cellForItemAtIndexPath:中设置一个断点来a) 确保它被调用,b) 看看还有什么问题。
标签: ios objective-c ipad uicollectionview