我正在尝试以编程方式向子视图添加collectionView。但是当我将项目数返回为1时,collection正在加载如此多的单元格。这里我在项目中使用SharkORM,会影响collectionView吗?我的实际要求是将有文件,图像集合需要存储在相关文件中。但是此集合视图未加载所需数量的单元格。任何人都可以解决这个问题。func createCollection(){ let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0) flowLayout.itemSize = CGSize(width: 82, height: 82) flowLayout.minimumInteritemSpacing = 0 flowLayout.scrollDirection = UICollectionView.ScrollDirection.vertical collectionView = UICollectionView(frame: CGRect(x: 10, y: 0, width: self.customView.frame.size.width-20, height: self.customView.frame.size.height), collectionViewLayout: flowLayout) collectionView.delegate = self collectionView.dataSource = self collectionView.register(UINib(nibName: "ReviewCollectionCellPage", bundle: nil), forCellWithReuseIdentifier: "ReviewCollectionCellPage") collectionView.backgroundColor = UIColor.clear customView.addSubview(collectionView) }extension ReviewViewController:UICollectionViewDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { print(finalImages.count) return finalImages.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { // print(finalImages) let cell : ReviewCollectionCellPage = collectionView.dequeueReusableCell(withReuseIdentifier: "ReviewCollectionCellPage", for: indexPath) as! ReviewCollectionCellPage cell.finalImage.image = UIImage(named: "images.png") collectionView.reloadData() return cell } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { return CGSize(width: 50, height: 50) } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { return UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5) }} 最佳答案 代码遇到无限循环。在cellForRow中,呼叫reloadData呼叫cellForRow呼叫reloadData呼叫cellForRow呼叫reloadData呼叫cellForRow呼叫reloadData呼叫cellForRow呼叫reloadData呼叫调用cellForRow调用reloadData ...其中🧨具有溢出异常在填充数据源数组之后,立即删除cellForRow中的collectionView.reloadData()并重新加载数据。关于ios - 线程1:EXC_BAD_ACCESS(代码= 2,地址= 0x16f913820),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57623917/
10-12 00:08