尝试将PFFile转换为UIImage并将其删除时,图像不显示

时间:2015-09-07 04:10:50

标签: ios swift parse-platform uiimage

当我单击一个单元格并希望它在新屏幕上显示相同的信息时,我的代码无法正常运行。

Text正常工作并显示在新视图中,但图像不会出现。我正在尝试将PFFile从Parse转换为UIImage并在数组中使用它,以便当我单击进入单元格并显示视图时,它将加载正确的图像和数据。我在Xcode 7 Beta 5。它没有给我任何错误,但仍然没有正确显示数据。

以下是必要的代码,如果需要更多代码来解决问题,我将很乐意提供。

(头等舱中的什么)

import Foundation
import Parse

class mainScreen: UIViewController, UICollectionViewDataSource {
var imageArray = [PFFile]()
var theDownloadedImages = [UIImage()]
var nameArray = [String]()
var priceArray = [String]()
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)    

{
    if segue.identifier == "cellInfo"
        {
        let indexPaths = self.collectionView!.indexPathsForSelectedItems()!
        let indexPath = indexPaths[0] as NSIndexPath
        let CI = segue.destinationViewController as! cellInfo

        let imageForCell = self.imageArray[indexPath.row] as PFFile

        imageForCell.getDataInBackgroundWithBlock { (data, error) -> Void in
              if let downloadedImage = UIImage(data: data!) {

                   self.theDownloadedImages.append(downloadedImage)

                    CI.image = self.theDownloadedImages[indexPath.row]
                    CI.name = self.nameArray[indexPath.row]
                    CI.price = self.priceArray[indexPath.row] 
              }
        }
}
}

(第二节课)

class cellInfo: UIViewController {

@IBOutlet weak var CILocation: UILabel!

@IBOutlet weak var CIImage: UIImageView!

@IBOutlet weak var CIPrice: UILabel!

@IBOutlet weak var CIName: UILabel!

var image = UIImage()
var name = String()
var price = String()
var location = String()

override func viewDidLoad() {
    super.viewDidLoad()

    self.CIImage.image = self.image
    self.CIName.text = self.name
    self.CIPrice.text = self.price
    self.CILocation.text = self.location
}

0 个答案:

没有答案