gpt4 book ai didi

ios - 应用程序运行时不断增加内存使用量(Swift)

转载 作者:行者123 更新时间:2023-11-28 15:45:54 24 4
gpt4 key购买 nike

我正在从文档目录中检索图像数据和字符串,并在 ViewController1 的 Collection View 中使用这些数据。然后通过单击 Collection View 单元格转到下一个 View Controller ViewController2 并再次从文档目录中检索图像数据和字符串,并在另一个 Collection View 中使用此数据。现在的问题是,当我每次从一个 View Controller 转到另一个 View Controller 并返回时,每次都会增加内存使用量,从而导致应用程序崩溃。这种内存增加的原因是什么,我将如何解决?

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
let cell: PhotoThumbnail = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! PhotoThumbnail

do{
let ta = foldersDirectoryPath + "/\(self.titles2[indexPath.item])"
print(ta)
let ti = try NSFileManager.defaultManager().contentsOfDirectoryAtPath(ta)
print(ti.count)
cell.amountLabel.layer.borderWidth = 1
cell.amountLabel.layer.borderColor = UIColor(red:16/255.0, green:56/255.0, blue:70/255.0, alpha: 1.0).CGColor
cell.amountLabel.text = "\(ti.count)"


}catch{

}

cell.setThumbnailImage(images[indexPath.item])
let str = titles2[indexPath.item]
let nameString = str.substringWithRange(Range<String.Index>(start: str.startIndex.advancedBy(24), end: str.endIndex.advancedBy(0)))

cell.nameLabel.text = nameString
print(dateArray[indexPath.item])
cell.dateLabel.text = dateArray[indexPath.item]

return cell
}


class PhotoThumbnail: UICollectionViewCell {

@IBOutlet weak var imgView : UIImageView!

@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var amountLabel: UILabel!

func setThumbnailImage(thumbnailImage: UIImage){
self.imgView.image = thumbnailImage
}

}

此代码用于第一个 Collection View 。

最佳答案

它创建了 View 一和 View 二的多个实例。您应该使用 segue 将数据从一个 View 传递到另一个 View ,然后返回。

关于ios - 应用程序运行时不断增加内存使用量(Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43061665/

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