import UIKit
import Photos
class GalleryController: UICollectionViewController,
UIImagePickerControllerDelegate,
UINavigationControllerDelegate {
var Receipts = [UIImage?]()
//Number of Views
override func numberOfSections(in collectionView: UICollectionView) -> Int {
print("return1")
return 1
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("self.receipts.count")
return self.Receipts.count
}
下面的代码无法正常工作,每次运行应用程序时都会出现此错误 -
SmartReceipts [738:137366] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“集合视图的数据源未从 -collectionView:cellForItemAtIndexPath 返回有效单元格:索引路径 {length = 2, path = 0 - 0}' *** 首先抛出调用堆栈: (0x186196364 0x1853dc528 0x186196238 0x186b317f4 0x1901010b0 0x18f6d7124 0x18f6d1de0 0x18f674f00 0x18a1d9998 0x18a1ddb20 0x18a14a36c 0x18a171b90 0x18f66a5c8 0x18613dedc 0x18613b894 0x18613be50 0x18605be58 0x187f08f84 0x18f6db67c 0x104484668 0x185b7856c) libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb)
对此的任何帮助将不胜感激。
需要修复的代码是下面的代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAtindexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "receipt", for: indexPath as IndexPath) as? PhotoCell
cell?.imageView.image = self.Receipts[indexPath.row]
print("Assigned to cell and should come up")
return cell!
}
}
它现在错误为这个错误,我不确定它是如何做到的?因为它将图像发送到数组但它没有显示在 UICollectionViewCell 中?