gpt4 book ai didi

xcode - dequeueReusableCellWithReuseIdentifier 崩溃 'could not dequeue a view of kind"UICollectionElementKindCell'

转载 作者:行者123 更新时间:2023-12-03 23:30:14 24 4
gpt4 key购买 nike

我遇到以下崩溃:

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



我的 ViewDidLoad 中有以下内容:
[self.collectionView registerClass:[UICollectionViewCell class] 
forCellWithReuseIdentifier:@"Cell"];

崩溃的行在 cellForItemAtIndexPath 回调中:
UICollectionViewCell *cell = [collectionView 
dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

我已经搜索了几个小时,但找不到任何解决方案。我试过对 UICollectionViewCell 进行子类化,但得到了同样的错误。

通过断点,我确定在执行 dequeueReusableCellWithReuseIdentifier 回调之前正在执行 registerClass 行。

最佳答案

我遇到这个问题是因为我正在调用 registerClass 之前 我正在实例化我的表 View 对象。工作代码:

self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView reloadData];

关于xcode - dequeueReusableCellWithReuseIdentifier 崩溃 'could not dequeue a view of kind"UICollectionElementKindCell',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13002711/

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