1
我資料圖片,也可作爲一個按鈕,當人點擊畫面中的圖像選擇顯示了,他們可以選擇他們想要爲他們的個人資料圖片使用的圖片,但imagePickerController
不會被調用,並解析數據庫圖像文件不會被調用。爲什麼會發生這種情況,我該如何解決?imagePickerController代表不叫,斯威夫特
class ProfileView: UIViewController, UIImagePickerControllerDelegate {
func userchange(sender: AnyObject){
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
// imagePicker.delegate = self
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
presentViewController(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
let user = PFUser.currentUser()
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let imageData = UIImageJPEGRepresentation(image, 0.05)
let imageFile = PFFile(name:"image.jpg", data:imageData!)
user!["ProPic"] = imageFile;
imageFile.save()
//NOTHING IS BEING PRINTED
print("called")
user!.saveInBackgroundWithBlock(nil)
self.dismissViewControllerAnimated(true, completion: nil)
}
}
}
檢查您是否在類中添加了'UIImagePickerControllerDelegate' –
是的,它被添加。 – coolmac
// imagePicker.delegate =自 爲什麼評論? –