ios - UICollectionView 出错
<p><p>我有一个非常简单的 Collection View ,但不知何故它总是崩溃。这是错误消息:</p>
<blockquote>
<p>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'</p>
</blockquote>
<p>还有我的代码:</p>
<pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseCellIdentifier = @"Reuse";
UICollectionViewCell *cell = ;
if (!cell) {
cell = [initWithFrame:CGRectMake(0, 0, 106, 95)];
}
UIImageView *imageView = [initWithFrame:CGRectMake(0, 0, 45, 45)];
imageView.image = ;
;
UILabel *name = [initWithFrame:CGRectMake(0, 0, 106, 15)];
name.text = @"user";
return cell;
}
</code></pre>
<p>救命!!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>似乎您没有在 Storyboard 上声明单元重用标识符,请执行以下步骤:</p>
<p><strong>- 选择 Storyboard上的单元格</strong></p>
<p> <img src="/image/XQuDg.png" alt="enter image description here"/> </p>
<p><strong>- 在“Collection Reusable view identifier”中输入重用标识符,在您的情况下,在此处输入“Reuse”</strong></p>
<p> <img src="/image/10OOQ.png" alt="enter image description here"/> </p>
<p>希望对您有所帮助..</p></p>
<p style="font-size: 20px;">关于ios - UICollectionView 出错,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/21772652/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/21772652/
</a>
</p>
页:
[1]