2016-04-30 51 views
0

我試圖更新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後,如何提供保存解析過程?

回答

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() 
      } 
     } 
    } 
+0

Happy programming dude :) –