I am building an app where at a certain question I am able to use a UIPicker to go back to go back to previous questions, however I either get an error or nothing happens when attempting to use the app.
Also, all of my pages Storyboard ID is the name I am calling them for the segue.
I have tried using a switch statement but I get too many errors so I have decided that if statements might go better.
Old Switch Statement:
public func textFieldDidEndEditing(_ textField: UITextField) {
let row = picker.selectedRow(inComponent: 0)
switch (row) {
case 0: storyboard?.instantiateViewController(withIdentifier: "Q1") as? Q1; performSegue(withIdentifier: "Q1", sender: self)
break;
case 1: storyboard?.instantiateViewController(withIdentifier: "Q2") as? Q2; performSegue(withIdentifier: "Q2", sender: self)
break;
case 2: storyboard?.instantiateViewController(withIdentifier: "Q3") as? Q3; performSegue(withIdentifier: "Q3", sender: self)
break;
case 3: storyboard?.instantiateViewController(withIdentifier: "Q4") as? Q4; performSegue(withIdentifier: "Q4", sender: self)
break;
case 4: storyboard?.instantiateViewController(withIdentifier: "Q5") as? Q5; performSegue(withIdentifier: "Q5", sender: self)
break;
case 5: storyboard?.instantiateViewController(withIdentifier: "Q6") as? Q6; performSegue(withIdentifier: "Q6", sender: self)
break;
default: break;
}
}
The error I get is 'Use of undeclared type "Q1"'
I am trying to do something along the lines of,
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int,
inComponent component: Int) {
DiffQuestion.text = data[row]
if (data == "Q1") {
storyboard?.instantiateViewController(withIdentifier: "Q1") as? Q1;
performSegue(withIdentifier: "Q1", sender: self)
}
}
Current error is on my if-statement "Binary operator '==' cannot be applied to operands of type '[String]' and 'String'" I know I probably structured it wrong, I'm still very new to all of this.
Aucun commentaire:
Enregistrer un commentaire