我正在尝试从parse.com提取数据到我的自定义单元格,该单元格中包含字符串和图像。我相信我是从parse.com错误地检索了我的PFFile,或者是正确地检索了PFFile,但是将文件错误地转换为UIImage。我收到的错误正在loadData()函数内发生。内容如下:找不到接受提供的参数的'init'的重载

信息

//Used to set custom cell
class Information {
    var partyName = ""
    var promoterName = ""
    var partyCost = ""
    var flyerImage: UIImage
    var promoterImage: UIImage

    init(partyName: String, promoterName: String, partyCost: String, flyerImage: UIImage, promoterImage: UIImage) {
        self.partyName = partyName
        self.promoterName = promoterName
        self.partyCost = partyCost
        self.flyerImage = flyerImage
        self.promoterImage = promoterImage
    }
}


解析提取功能

func loadData() {
    var findDataParse:PFQuery = PFQuery(className: "flyerDataFetch")
    findDataParse.findObjectsInBackgroundWithBlock{
        (objects: [AnyObject]?, error: NSError?) -> Void in
        if (error == nil) {
            for object in objects! {
                var eventImage0 : UIImage
                var eventImage10 : UIImage
                let userImageFile = object["partyFlyerImage"] as! PFFile
                userImageFile.getDataInBackgroundWithBlock {
                    (imageData: NSData?, error: NSError?) -> Void in
                    if error == nil {
                        let eventImage = UIImage(data:imageData!)
                        eventImage0 = eventImage!
                    }
                }
                let userImageFile1 = object["partyPromoterImage"] as! PFFile
                userImageFile1.getDataInBackgroundWithBlock {
                    (imageData1: NSData?, error1: NSError?) -> Void in
                    if error1 == nil {
                        let eventImage1 = UIImage(data:imageData1!)
                        eventImage10 = eventImage1!
                    }
                }
//Error below
                var party1 =  Information(partyName: (object["partyName"] as? String)!, promoterName: (object["partyPromoterName"] as? String)!,partyCost: (object["partyCost"] as? String)!, flyerImage: UIImage(data: eventImage0)!, promoterImage: UIImage(data: eventImage10)!)

                self.arrayOfParties.append(party1)
            }
        }
        self.tableView.reloadData()

    }
}

最佳答案

您正在后台从Parse中获取数据,但在主线程上进行处理。尝试这个:

func loadData() {
    var findDataParse:PFQuery = PFQuery(className: "flyerDataFetch")
    findDataParse.findObjectsInBackgroundWithBlock{
    (objects: [AnyObject]?, error: NSError?) -> Void in
        if (error == nil) {
            for object in objects! {
                var eventImage0 : UIImage
                var eventImage10 : UIImage
                let userImageFile = object["partyFlyerImage"] as! PFFile
                userImageFile.getDataInBackgroundWithBlock {
                    (imageData: NSData?, error: NSError?) -> Void in
                    if error == nil {
                        let eventImage = UIImage(data:imageData!)
                        eventImage0 = eventImage!
                        let userImageFile1 = object["partyPromoterImage"] as! PFFile
                        userImageFile1.getDataInBackgroundWithBlock {
                            (imageData1: NSData?, error1: NSError?) -> Void in
                            if error1 == nil {
                                let eventImage1 = UIImage(data:imageData1!)
                                eventImage10 = eventImage1!

                                var party1 =  Information(partyName: (object["partyName"] as? String)!, promoterName: (object["partyPromoterName"] as? String)!, partyCost: (object["partyCost"] as? String)!, flyerImage: UIImage(data: eventImage0)!, promoterImage: UIImage(data: eventImage10)!)

                                self.arrayOfParties.append(party1)
                            }
                        }
                    }
                }
            }
        }
        self.tableView.reloadData()

    }
}

10-08 15:40