gpt4 book ai didi

ios - 线程1 : EXC_BAD_ACCESS (code=2, 地址=0x16f913820)

转载 作者:行者123 更新时间:2023-11-29 05:30:39 24 4
gpt4 key购买 nike

我正在尝试以编程方式将collectionView添加到 subview 中。但是当我返回项目数为1时,集合正在加载大量单元格。这里我在我的项目中使用SharkORM,它会影响collectionView吗?我的实际情况要求是我将拥有文件,图像集合需要存储在相关文件中。但是此 Collection View 未加载所需数量的单元格。任何人都可以帮助解决此问题。

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...其中 🧨 出现溢出异常

删除cellForRow中的collectionView.reloadData()并在填充数据源数组后立即重新加载数据。

关于ios - 线程1 : EXC_BAD_ACCESS (code=2, 地址=0x16f913820),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57623917/

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