0

I am trying to use segues to pass the data entered in the partyID text field to the partyID label in a separate view controller. However, I am getting errors in my code.

class PartyViewController: UIViewController {

    // CALLS LOGIN VC
    var LoginViewController: LoginViewController?

    override func viewDidLoad() {
        super.viewDidLoad()


        // Do any additional setup after loading the view.
    }
    @IBOutlet weak var partyID: UITextField!

    var token = String()

    @IBAction func startParty(_ sender: UIButton) {
        self.performSegue(withIdentifier: "partyVCtoGuestPartyVC", sender: self)
        performSegue(withIdentifier: "hostStartParty", sender: self)
        //LoginViewController?.fetchSpotifyProfile(accessToken )

        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
               if(segue.identifier == "partyVCtoGuestPartyVC"){
               let GuestPartyVC = segue.destination as! GuestPartyViewController
               GuestPartyVC.partyID = partyID.text
           }

And here is the view controller I am trying to pass the data to:

class GuestPartyViewController: UIViewController {
    @IBOutlet weak var partyID: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()


        partyIDLabel.text = partyID
        // Do any additional setup after loading the view.
    }

I get errors in my override func in LoginVC and then in the partyIDlabel.text in the GuestPartyVC.

3
  • What errors? At least prepare(for segue must be on the same level as viewDidLoad outside of the IBAction. And why do you perform two segues simultaneously? Commented Mar 31, 2020 at 20:12
  • After doing a combination of the answers on this page I get a thread1 error: SIGABRT in appdelegate Commented Apr 1, 2020 at 20:47
  • setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Commented Apr 1, 2020 at 20:49

3 Answers 3

1

In GuestPartyViewController

class GuestPartyViewController: UIViewController {
    @IBOutlet weak var partyIDLabel: UILabel!

    var partyID: String? 

    override func viewDidLoad() {
        super.viewDidLoad()
        partyIDLabel.text = partyID ?? ""
    }
}

In PartyViewController

class PartyViewController: UIViewController {

    @IBOutlet weak var partyID: UITextField!


    @IBAction func startParty(_ sender: UIButton) {
        self.performSegue(withIdentifier: "partyVCtoGuestPartyVC", sender: self)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "partyVCtoGuestPartyVC",
            let GuestPartyVC = segue.destination as? GuestPartyViewController {
            GuestPartyVC.partyID = partyID.text
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

After doing a combination of the answers on this page I get a thread1 error: SIGABRT in appdelegate
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
Make sure your class names updated correctly, also your segue identifier "partyVCtoGuestPartyVC" is updated in storyboard.. might be a small spelling mistake
0

The IBOutlet is weak and may not be instantiate when you pass the text.

Could you try to pass the text in a property, then assign it in the viewDidLoad ?

class GuestPartyViewController: UIViewController {

@IBOutlet weak var partyID: UILabel!

var passedText: String?

override func viewDidLoad() {
    super.viewDidLoad()

   if let unwrappedPassedText = passedText {
      partyIDLabel.text = partyID
   }
}

// In the other controller

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if(segue.identifier == "partyVCtoGuestPartyVC") {
        let GuestPartyVC = segue.destination as! GuestPartyViewController
        GuestPartyVC.passedText = partyID.text
    }

2 Comments

After doing a combination of the answers on this page I get a thread1 error: SIGABRT in appdelegate
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
0

first change the call of login VC

var LoginViewController = LoginViewController()

then put this before the view did load method

@IBOutlet weak var partyID: UITextField!

and can you send the error that you get

2 Comments

After doing a combination of the answers on this page I get a thread1 error: SIGABRT in appdelegate
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.