我如何安排代码的哪一部分首先工作

时间:2016-04-30 15:18:17

标签: ios swift parse-platform

我正在尝试更新parse.com中的图像存储。我的视图上有一个imageview,该imageview上有一个默认图像。我可以从图书馆选择照片,我可以用我从图书馆中选择的照片更改我的图像浏览图像。但是我的代码仍保存默认图像以解析我从库中选择的图像。

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
    self.dismissViewControllerAnimated(true, completion: nil)
    profileImage.image = image
}

var objectIds = [String]()
@IBAction func changePp(sender: AnyObject) {
    var image = UIImagePickerController()
    image.delegate = self
    image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    image.allowsEditing = false
    self.presentViewController(image ,animated: true,completion: nil)

    var queryU = PFQuery(className:"ProfilePhoto")
    queryU.getObjectInBackgroundWithId(self.objectIds[0]) {
        (Pp: PFObject?, error: NSError?) -> Void in
        if error != nil {
            print(error)
        } else if let Pp = Pp {


            let imageData = UIImagePNGRepresentation(self.profileImage.image!)
            let imageFile = PFFile(name: "pImage.png",data: imageData!)
            Pp["profilePhoto"] = imageFile


            Pp.saveInBackground()
        }
    }


    }

从库中选择照片并设置为我的imageview后,如何为解析过程提供保存?

1 个答案:

答案 0 :(得分:2)

由于您在从图库中选择图像之前在解析时保存图像,因此正在发生这种情况。所以请在从库中选择图像后再进行操作。

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
        self.dismissViewControllerAnimated(true, completion: nil)
        profileImage.image = image


    var queryU = PFQuery(className:"ProfilePhoto")
        queryU.getObjectInBackgroundWithId(self.objectIds[0]) {
            (Pp: PFObject?, error: NSError?) -> Void in
            if error != nil {
                print(error)
            } else if let Pp = Pp {


                let imageData = UIImagePNGRepresentation(self.profileImage.image!)
                let imageFile = PFFile(name: "pImage.png",data: imageData!)
                    wait(w_status: 1000)
                Pp["profilePhoto"] = imageFile


                Pp.saveInBackground()
            }
        }
    }