Ios UICollectionViewCell没有reuseIdentifier
我有一个在UICollectionView中显示图像的应用程序,我现在遇到的问题是,每当我单击将我带到带有UICollectionView的视图控制器的按钮时,应用程序就会崩溃,并显示以下消息: 由于未捕获异常而终止应用程序 “NSInternalInconsistencyException”,原因:“单元格从 -collectionView:cellForItemAtIndexPath:没有reuseIdentifier-必须通过调用 -dequeueReusableCellWithReuseIdentifier:forIndexPath:' 我的电池完好无损,所以我不知道它为什么会崩溃Ios UICollectionViewCell没有reuseIdentifier,ios,swift,Ios,Swift,我有一个在UICollectionView中显示图像的应用程序,我现在遇到的问题是,每当我单击将我带到带有UICollectionView的视图控制器的按钮时,应用程序就会崩溃,并显示以下消息: 由于未捕获异常而终止应用程序 “NSInternalInconsistencyException”,原因:“单元格从 -collectionView:cellForItemAtIndexPath:没有reuseIdentifier-必须通过调用 -dequeueReusableCellWithReuse
extension SavedPhotoVC: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SAVED_CELL, for: indexPath) as? SavedCell {
let flickerPhoto = itemArray[indexPath.row]
cell.configueCell(flickerPhotoModel: flickerPhoto, index: indexPath.item)
return cell
}
return SavedCell()
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return itemArray.count
}
可以根据请求添加更多代码。问题就在这里
return SavedCell()
您不应该返回空单元格,因为集合稍后会将其出列并在没有标识符的情况下找到它,直接的方法是
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SAVED_CELL, for: indexPath) as! SavedCell
let flickerPhoto = itemArray[indexPath.row]
cell.configueCell(flickerPhotoModel: flickerPhoto, index: indexPath.item)
return cell
}
您是否使用保存的单元格注册了保存的单元格?是。我在我的故事板中这样做了,你能设置一个断点并检查实际执行的返回吗?返回单元格或返回SavedCell。未调用返回单元格。应用程序崩溃并显示相同错误您能告诉我们您如何在故事板中注册您的单元格,以及如何设置已保存单元格的值吗?我正在使用collectionview@Sh_Khan请帮忙回答这个问题。我已经连续三天在做这件事了