【发布时间】:2019-03-26 03:16:50
【问题描述】:
我是一名新开发人员,我的应用有一个包含 32 张图片的集合视图(水平滚动)。我为图像、标签和文本创建了数组。 当我到达列表末尾时,应用程序崩溃了。无论我的图像大小如何,我都会收到“来自调试器的消息:由于内存问题而终止”。我使用了 Instruments 工具,这似乎表明图像没有发布。
我尝试调整图像大小但没有成功。我也试过用autoreleasepool,可能我用错了。
我的图像数组是这样设置的,图像 1-32。
let imageArray = [UIImage (named: "1"), UIImage (named: "2"), etc.]
这是我的收藏视图:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MainCollectionViewCell", for: indexPath) as! MainCollectionViewCell
cell.imgImage.image = imageArray [indexPath.row]
cell.lblImageName.text = nameArray [indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let desVC = mainStoryboard.instantiateViewController(withIdentifier: "DetailViewController") as! DetailViewController
desVC.image = imageArray[indexPath.row]!
desVC.name = nameArray[indexPath.row]
desVC.text = textArray[indexPath.row]
self.navigationController?.pushViewController(desVC, animated: true)
}
【问题讨论】:
标签: arrays swift memory xcode10.1