0

I am building a simple app that has a PickerView with 3 selections that should link to 3 viewControllers each named FirstViewController, SecondViewController and ThirdViewController.
But I am getting this error

> NSInvalidArgumentException', reason: 'Receiver (<Scroller.ViewController: 0x7ff7b5e0b670>) has no segue with identifier 'SecondSegue'

I have three options in the picker and a button to go to that selection's viewController:

enter image description here

My code below works on first loading then crashes

import UIKit


class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

    @IBAction func continueButtonPressed(_ sender: AnyObject) {
        self.performSegue(withIdentifier: "\(chosenState)Segue", sender: nil)
        print("no chance")
    }
    @IBOutlet weak var pickerView: UIPickerView!

    var pickerData = ["First","Second","Third"]
    var chosenState = ""

    override func viewDidLoad() {
        super.viewDidLoad()
     print("Help")
        pickerView.delegate = self
        pickerView.dataSource = self
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // The number of columns of data


    // The number of rows of data
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return pickerData.count
    }

    // The data to return for the row and component (column) that's being passed in
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return pickerData[row]
    }
    //Called when the user changes the selection...
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        chosenState = pickerData[row]
    }

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }
}

can anyone help me understand how to fix this ?

Have I named the Segues ok? They are all named the same - is that correct?

Larme
  • 24,190
  • 6
  • 51
  • 81
  • Hi Boober Bunz Hmm I’m missing something and I can’t stop what you are saying can you give me a little more help regards Jeremy – Jeremy Griffin Mar 22 '18 at 15:54
  • " They are all named the same - is that correct?" No. According to your code they should be named `FirstSegue`, `SecondSegue" and `ThirdSegue`. – Larme Mar 26 '18 at 08:20
  • Please **read** the error message. It's pretty clear. – vadian Mar 26 '18 at 08:32

2 Answers2

1

You have to set the segue identifier to second view controller as SecondSegue

DionizB
  • 1,487
  • 2
  • 10
  • 20
0

It seems your SecondSegue to your second UIViewController has not been named properly.

Be careful, it is case sensitive, it must be named precisely SecondSegue. And after having changed the name, don't forget to validate your input with the return key.

Zaphod
  • 6,758
  • 3
  • 40
  • 60