--Screen transition when the button is pressed --Screen transition under conditions --Screen transition by passing variables
I might add it.
control key
and drag and drop it on the screen you want to transition to.control key
and drag and drop it on the screen you want to transition to.if
ViewController.swift
if conditional expression{
//Write the ID set in "3"
performSegue(withIdentifier: "next", sender: nil)
}
prepare
to prepare to pass the valueIf you select the one that says prepare
, it will be completed automatically.
ViewController.swift
//Variable you want to pass
var face = "(´ ・ ω ・ `)"
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//Write the controller name of the transition destination. Here NextViewController
let nextVC = segue.destination as! NextViewController
//Substitute the variable you want to pass to the variable name (described later) defined at the receiving destination
nextVC.nextFace = face
}
NextViewController.swift
//For example, set up a Label and receive it there
@IBOutlet weak var nextLabel: UILabel!
var nextFace = ""
override func viewDidLoad() {
super.viewDidLoad()
nextLabel.text = nextFace
}
(´ ・ ω ・ `)
is displayed on the transition destination Label.
In a practical place, I think it is better to pass the calculated answer or the transition destination.
Recommended Posts