我有一个非常简单的 Collection View ,但不知何故它总是崩溃。这是错误消息:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier Reuse - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
还有我的代码:
- (UICollectionViewCell *)collectionViewUICollectionView *)collectionView cellForItemAtIndexPathNSIndexPath *)indexPath
{
static NSString *reuseCellIdentifier = @"Reuse";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseCellIdentifier forIndexPath:indexPath];
if (!cell) {
cell = [[UICollectionViewCell alloc]initWithFrame:CGRectMake(0, 0, 106, 95)];
}
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 45, 45)];
imageView.image = [UIImage imageNamed"image_name"];
[cell addSubview:imageView];
UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 106, 15)];
name.text = @"user";
return cell;
}
救命!!
似乎您没有在 Storyboard 上声明单元重用标识符,请执行以下步骤:
- 选择 Storyboard上的单元格
- 在“Collection Reusable view identifier”中输入重用标识符,在您的情况下,在此处输入“Reuse”
希望对您有所帮助..
关于ios - UICollectionView 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21772652/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |