ios – UICollectionView – 不显示单元格

我想要实现的是一个带有UICollectionView的3×3表.但是在运行应用程序时它不会显示任何单元格.它确实显示了CollectionView的背景颜色(我设置为蓝色)有人可以帮助我吗?

我所做的是创建一个故事板,只需将一个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;
}

我将单元格的标识符设置为“单元格”,并在CollectionView和自定义UICollectionViewController之间建立了一个数据源的出口连接并进行委托.一切都很好.
那我还缺少什么?在使用编辑器进行所有这些调整之前,它不应该显示出一些方法吗?

解决方法

See my answer here,简而言之,如果您正在使用故事板,则需要删除此行:
// Register cell classes
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...