//画面遷移

//

 

import UIKit

 

class ViewController: UIViewController {

    

    @IBOutlet var label: UILabel!

    

    var count = 0

    

    override func viewDidLoad() {

        super.viewDidLoad()

    }

 

    @IBAction func plus(_ sender: Any) {

        count = count + 1

        label.text = String(count)

        

        if count == 10 {

            //count = 0

            //任意のタイミングで画面遷移

            //storyboardで、「Segue」を選択して、ID「next」を付ける

            //performSegue(withIdentifier: "next", sender: nil)

            

            //ナビゲーションコントローラーを使った画面遷移

            let nextVC = storyboard?.instantiateViewController(withIdentifier: "next") as! NextViewController

            nextVC.count2 = count

            

            navigationController?.pushViewController(nextVC, animated: true)

        }

    }

    

    //値を渡しながら画面遷移

    //override = 「自動的に読まれる」という意味

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        let nextVC = segue.destination as! NextViewController

        nextVC.count2 = count

    }

 

}

 

最後まで、読んでいただきありがとうございます。

 

 

〜・〜P S〜・〜

メルカリで、懐かしい昭和のレコードなどを出品しています。

興味がありましたら、リンクを貼りますので、覗いて見て下さい。

懐かしくて、昭和の頃の思い出が脳裏に蘇りますよ。

 

funatetu1978