我遇到以下崩溃:
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之前,我正在实例化我的表视图对象.工作代码:
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];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。