0
我正在嘗試設置註冊頁面,以便用戶可以設置個人資料圖片,但只要按下注冊按鈕並且它會繼續註冊頁面由於配置文件圖片代碼而不斷崩潰。這是按鈕設置個人資料圖片嘗試設置PFUser的個人資料圖片時發生致命錯誤
@IBAction func setProfilePicture(sender: AnyObject) {
let myPickerController = UIImagePickerController()
myPickerController.delegate = self
myPickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(myPickerController, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
profilePictureIV.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismissViewControllerAnimated(true, completion: nil)
}
,這是發送數據的viewDidLoad()
方法
let newUser = PFUser()
let profilePicture = UIImageJPEGRepresentation((profilePictureIV?.image)!, 1)
if(profilePicture != nil) {
let profilePictureImageFile = PFFile(data: profilePicture!)
newUser["profilePicture"] = profilePictureImageFile
}
...
}
,保持崩潰是讓profilePicture行解析代碼... 。線給出一個錯誤: 致命錯誤:意外地發現零而展開的可選值 (LLDB)
不,仍然無法正常工作。它給了我一個錯誤,修復它,並用'(profilePictureIV?.image)替換'profilePictureIV?.image'! –
我用另一個替代品 – vadian
OH YAY更新了答案!非常感謝你!! –