我试图设置注册页面,以便用户可以设置个人资料图片,但是一旦我按下注册按钮并进入注册页面,它就会因为个人资料图片代码而不断崩溃。这是设置头像的按钮
@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
}
...
}
不断崩溃的行是 let profilePicture.... 行给出错误:致命错误:在展开可选值(lldb)时意外发现 nil