我的表格视图单元格需要以高分辨率显示10-30张图像(用于打印目的)。当我们有15张照片时,该应用程序得到了内存警告和崩溃。如何在tableview单元格中处理照片的最佳方式,以便应用程序不会崩溃?
班级数据
class dataImage {
var userId: String
var value: Double
var photo: UIImage?
var croppedPhoto: UIImage?
init(userId:String, value: Double, photo: UIImage?, croppedPhoto: UIImage?){
self.userId = userId
self.value = value
self.photo = photo
self.croppedPhoto = croppedPhoto
}
}
查看控制器
func loadDataPhoto(){
for asset in photos{
autoreleasepool{
asset.fetchOriginalImageWithCompleteBlock({ image, info in
let images = image
let croppedImage: UIImage = self.photoToCrop(image: image!)
let data1 = dataImage(userId: "goodies\(completed+1)", value: 1.0, photo: images, croppedPhoto: croppedImage)
datas += [data1]
print("*")
//print(data1.userId)
self.tableView.reloadData()
})
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "reviewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ReviewTableViewCell
let data = datas[indexPath.row]
let tag = indexPath.row
cell.tag = tag
autoreleasepool { () -> () in
cell.imageView.image = data.croppedPhoto
}
cell.countStepper.value = datas[indexPath.row].value
cell.stepperLabel.text = "x \(Int(cell.countStepper.value))"
cell.delegate = self
return cell
}