Unexpectedly found nil while unwrapping an Optional value

Hi all,

 

 

This is my code:

 

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var textField: UITextField!

    @IBAction func saveButton(sender: UIBarButtonItem) {

        println(“The button was clicked”)

        self.dismissViewControllerAnimated(true, completion: nil)

        PetTable.Profile1.textLabel!.text = “Jim”

    }

    @IBAction func cancelButton(sender: UIBarButtonItem) {

    }

  

    override func viewDidLoad() {

        super.viewDidLoad()

        /

    }

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        /

    }

    func textFieldShouldReturn(textField: UITextField) -> Bool {

        textField.resignFirstResponder()

        return true;

    }

}

 

 

var PetTable: PetTableViewController = PetTableViewController()

 

class PetTableViewController: UITableViewController{

  

    @IBOutlet var Profile1: UITableViewCell!

    @IBOutlet var Profile2: UITableViewCell!

    @IBOutlet var Profile3: UITableViewCell!

    @IBOutlet var Name1: UILabel!

  

    override func viewDidLoad() {

        super.viewDidLoad()

        Name1.text? = “It Worked!”

 

 

 

I am trying to change a table view cell’s label from another view when a bar button is clicked and I get an error saying: “fatal Error: Unexpectedly found nil while unwrapping an Optional value.

I really need help on this one as I have searched online for this topic and tried many things but nothing has worked. I would love to know if there is anything that can be done to solve this error or whether there is another war of changing a label from a different view.

 

Thanks,

James

Powered by WPeMatico

About

You may also like...

Comments are closed.