gpt4 book ai didi

iphone - 使用 dequeueReusableCellWithReuseIdentifier 的标识符问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:53:16 25 4
gpt4 key购买 nike

当我在模拟器中运行我的应用程序时,我遇到了这个运行时错误。

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier PlayingCard - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

它崩溃的行是

UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlayingCard"
forIndexPath:indexPath];

在方法中

-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath{}

据我了解,该错误意味着标识符“PlayingCard”与 CollectionView 中 CollectionViewCells 的任何标识符都不匹配,但我已确保 Storyboard中的标识符相同。

谢谢你的帮助

最佳答案

你的错误告诉你的问题的细节

must register a nib or a class for the identifier or connect a prototype cell in a storyboard

如果仅通过代码创建 UICollectionViewCell 类,请在 viewDidLoad 中为 collectionView 使用注册类

 [self.collectionView registerClass:[YourCell class] forCellWithReuseIdentifier:@"PlayingCard"];

如果你通过Xib创建UICollectionViewCell,使用registerNib

如果将 UICollectionViewCell 拖到 Storyboard中,请指定 UICollectionView 类并重用标识符

我想你忘了在 Storyboard中为你的 Cell 指定类名

关于iphone - 使用 dequeueReusableCellWithReuseIdentifier 的标识符问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19340823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com