I am trying to use Parse to edit profile and after I put the code in when I launch the app I clicked the button I made to edit profile and I get this:
fatal error: unexpectedly found nil while unwrapping an Optional value
The Segue I have leading to the edit profile controller does not open and the app crashes. When the Parse code is not implemented the segue to the view controller opens just fine.
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) {
}
}