Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
If I understood everything correctly, you need to pass data between controllers using segue.
We create a variable in the class of the second controller, to which we will pass the desired value.
Next, create a button on the first controller and drag the segway from the button to the second controller. and specify its identifier.
Below is the code for the second controller. Just a Label, and assign the value of the "name" variable to the "text" property of this label.
class SecondViewController: UIViewController {
var name = ""
@IBOutlet var username: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
username.text = name
}
}
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard segue.identifier == "YourIdentificator" else { return }
guard let destination = segue.destination as? SecondViewController else { return }
destination.name = "Вася"
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question