我是iOS新手,我想上传图片进行解析。这是代码
func imagePickerController(picker : UIImagePickerController, didFinishPickingMediaWithInfo info : [NSObject : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
let scaledImage = self.scale(pickedImage, and : CGSizeMake(100, 100))
let imagedata = UIImagePNGRepresentation(scaledImage)
let imageFile = PFFile(data : imagedata)
PFUser.currentUser()?.setObject(imageFile, forKey : "profileImage")
PFUser.currentUser()!.saveInBackgroundWithBlock {
(success : Bool, error : NSError?) -> Void in
if (success) {
println("success")//Neither success nor fail is printing
} else {
println("fail")
}
}
// print("")
dismissViewControllerAnimated(true, completion : nil)
let viewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("yoyo") as? UIViewController
self.presentViewController(viewcontroller!, animated : true, completion : nil)
}
}
问题是databrowser没有填充图像。感谢。
答案 0 :(得分:0)
您可能希望使用saveInBackgroundWithBlock
这样的
var parseImageFile = PFFile(name: "uploaded_image.png", data: imageData)
posts["imageFile"] = parseImageFile
posts.saveInBackgroundWithBlock({
(success: Bool, error: NSError?) -> Void in
if error == nil {
//back to home
println("Success")
self.performSegueWithIdentifier("something", sender: self)