我想使用解析來編輯配置文件,並在我把代碼放入啓動應用程序時,我點擊了我所做的按鈕編輯個人資料,我得到這個:當我執行解析我得到「致命錯誤:意外地發現零,而解包可選值」
fatal error: unexpectedly found nil while unwrapping an Optional value
塞格我導致編輯配置文件控制器不打開,應用程序崩潰。當解析代碼沒有被執行時,視圖控制器的繼續打開就好了。
import UIKit
import Parse
class EditProfileViewController: UIViewController {
@IBOutlet weak var profilePictureImageView: UIImageView!
@IBOutlet weak var firstNameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var repeatPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Load user details
let userFirstName = PFUser.currentUser()?.objectForKey("first_name") as! String
let userLastName = PFUser.currentUser()?.objectForKey("last_name") as!String
firstNameTextField.text = userFirstName
lastNameTextField.text = userLastName
if(PFUser.currentUser()?.objectForKey("profile_picture") != nil)
{
let userImageFile:PFFile = PFUser.currentUser()?.objectForKey("profile_picture") as! PFFile
userImageFile.getDataInBackgroundWithBlock({ (imageData: NSData?, error: NSError?) -> Void in
self.profilePictureImageView.image = UIImage(data: imageData!)
})
}
let image = UIImage(named: "navbar.png")
self.navigationController!.navigationBar.setBackgroundImage(image,forBarMetrics: .Default)
var nav = self.navigationController?.navigationBar
nav?.tintColor = UIColor.whiteColor()
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]; self.navigationController!.navigationBar.titleTextAttributes = titleDict as [NSObject : AnyObject]
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true;
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
self.view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func doneButtonTapped(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func chooseProfileButtonTapped(sender: AnyObject) {
}
@IBAction func saveButtonTapped(sender: AnyObject) {
}
}
你在哪一行得到t他的錯誤? –
我不知道如何找到這個。我仍然在學習,但我很確定這是「讓userImageFile:PFFile = PFUser.currentUser()?. objectForKey(」profile_picture「)as!PFFile」 –
可能的重複[什麼是致命錯誤:意外地發現無展開一個可選值「的意思?](http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – jtbandes