[Swift] Simple screen transition summary

pattern

--Screen transition when the button is pressed --Screen transition under conditions --Screen transition by passing variables

I might add it.

Screen transition when the button is pressed

  1. Install buttons like "NEXT" or "Next".
  2. Click the button while pressing the control key and drag and drop it on the screen you want to transition to.

スクリーンショット 2020-12-05 19.11.08.png

  1. Then an option will appear, so select it.

スクリーンショット 2020-12-05 19.18.59.png

Screen transition by condition

  1. Click the icon at the top while pressing the control key and drag and drop it on the screen you want to transition to.

スクリーンショット 2020-12-05 19.21.19.png

  1. As with "3" above, options will appear, so select them.

スクリーンショット 2020-12-05 19.21.26.png

  1. Click the screen transition arrow (called "Segue") and give it a name (or ID) with Identifier.

7fddf47749010b61ea2655b2e425fe18.png

  1. Write the code in if

ViewController.swift


if conditional expression{
      //Write the ID set in "3"
      performSegue(withIdentifier: "next", sender: nil)
    }

Screen transition by passing variables

  1. Write a method for prepare to prepare to pass the value

If you select the one that says prepare, it will be completed automatically.

スクリーンショット 2020-12-05 20.05.51.png

hand over

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
  }

receive

 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

[Swift] Simple screen transition summary
Screen transition method
Screen transition memorandum
JavaFX8 screen transition
uri library simple summary
Swift Iterative Sentence Summary
[Swift] Simple implementation of UIImageView
How to transition from the [Swift5] app to the iPhone settings screen
Swift conditional branch statement summary
[Swift] Summary about Bool type
Android development ~ Screen transition (intent) ~
[Note] MVC model simple summary
Screen transition Information transfer memorandum
Animation settings at screen transition
Screen transition with swing, java
[Swift] Implement screen transition and pass by value with Segue and present
Screen transition using Intent in Kotlin
[Rails] How to prevent screen transition
Screen transition by Post method [Java]
[Java Swing] Screen transition by CardLayout
Android application: Let's explain the mechanism of screen transition with simple code