Home>

I'd like to change the text that appears in the textfield when I typed in the second label by picker operation, but it doesn't work. As a construction measure, an error occurred when trying to change the character with an if statement by making another screen transition to one screen transition code. I don't understand screen transitions at all, so please tell me what to do.

import UIKit
class secondViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
    @IBOutlet weak var seibetupicker: UIPickerView!
    @IBOutlet weak var agepicker: UIPickerView!
var selectedSeibetu: String?
    override func viewDidLoad () {
        super.viewDidLoad ()
        seibetupicker.delegate = self
        seibetupicker.dataSource = self
        agepicker.delegate = self
        agepicker.dataSource = self
 override func didReceiveMemoryWarning () {
        super.didReceiveMemoryWarning ()
        agepicker.numberOfRows (inComponent: 0)
        // Dispose of any resources that can be recreated.
    }
    func numberOfComponents (in pickerView: UIPickerView)->Int {
        // number of columns to display
        return 1
    }
    func pickerView (_ pickerView: UIPickerView, numberOfRowsInComponent component: Int)->Int {
        switch pickerView {
        case agepicker:
            return agedataList.count
        case seibetupicker:
            return seibetudataList.count
        default:
            fatalError ()
        }
    }
func pickerView (_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int)->String? {
        switch pickerView {
        case agepicker:
            return agedataList [row]
        case seibetupicker:
            return seibetudataList [row]
       default:
            fatalError ()
        }
    }
 func pickerView (_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if pickerView == seibetupicker {
            selectedSeibetu = seibetudataList [row]
        }
    }
    override func prepare (for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "ThirdViewController" {
            guard let thirdVC = segue.destination as? ThirdViewController else {
                fatalError ()
            }
            let seibetu = seibetupicker.selectedRow (inComponent: 0)
            if (seibetu == 2) {
                thirdVC.Datalist = 2
            } else {
                thirdVC.Datalist = 0
            }
        }
    }
}
var image: UIImage?
    var arigatou = "Thank you"
    var douitasimasite = "You are welcome"
 @IBAction func display (_ sender: Any)
    {
        self.yourlavel.text = self.textfield.text
        if arigatou == self.textfield.text {
            yourlavel.text = String ("You are welcome")
        } else if douitasimasite == self.textfield.text {
            yourlavel.text = String ("No, no")
        }
  • Answer # 1

    This is the answer to the first question, but when you answered the previous question, I think you used the prepare function to pass by value. And to pass by value, there is an excuse if there is a receiver and a receiver.
    For this reason, I feel like I added a variable calledDataListto the third-view controller that is the recipient (although I'm already confused).
    If there are multiple values ​​that you want to pass this time, it will be completed if you prepare as many recipients and recipients.

    The answer to the second question

      

    Preferably pasting each VC class

    I think I wrote it in the comment field like

    , but I don't understand this point, so there is no answer. I can't simply answer.