LoginSignup
0
0

More than 1 year has passed since last update.

【UIKit】画面遷移の方法

Last updated at Posted at 2022-07-04

StoryBoardで遷移

Controlを押しながらButtonをViewControllerにドラッグします。
スクリーンショット 2022-07-04 19.47.37.png
Action Segueの中から遷移方法を選択します
スクリーンショット 2022-07-04 19.47.48.png

コードで遷移

「Cocoa Touch Class」を選択して「Next」を押します。
スクリーンショット 2022-07-04 20.19.33.png
Class名を決めます。
今回は「TestViewController」としました。
入力が完了したら「Next」を押します。
スクリーンショット 2022-07-04 20.20.51.png
追加したViewControollerを「TestViewController」に紐付けます。
スクリーンショット 2022-07-04 20.23.25.png
「TestViewController」を紐付けたViewControllerに「Stroyboard ID」を設定します。
今回は「TestView」としました。
スクリーンショット 2022-07-04 20.25.43.png

Optionを押しながら「ViewController」を選択すると画像のように2画面表示になります。
Controlを押しながらButtonをViewControllerにドラッグします。
スクリーンショット 2022-07-04 20.30.15.png
以下の画像のように設定を行います。
Nameは「tapAction」としました
スクリーンショット 2022-07-04 20.31.27.png
tapActionを以下のように変更します。

@IBAction func tapAction(_ sender: Any) {
    let testViewController = self.storyboard?.instantiateViewController(withIdentifier: "TestView") as! TestViewController
    self.present(testViewController, animated: true, completion: nil)
}

スクリーンショット 2022-07-04 21.57.08.png

おわり

UIKitは慣れていないので何か間違っているところがあるかも知れません笑
間違っている箇所があれば編集リクエストかコメントで教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0