0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

コードでViewを表示させるときにViewController をUINavigationControllerに埋め込みさせたい

Posted at

はじめに

コードでViewを表示させるときにViewController
をUINavigationControllerに埋め込みさせたいときのメモ

Storyboardを使わないプロジェクトの設定をします

やり方はこちらの記事どうぞ.
https://qiita.com/Imael/items/e908aef1e6fc077f29fc

コードです

import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let scene = (scene as? UIWindowScene) else { return }
        let window = UIWindow(windowScene: scene)
        let vc = ViewController()
        // NavigationControllerのルートビューにする
        let nvc = UINavigationController(rootViewController: vc)
        window.rootViewController = nvc
        window.makeKeyAndVisible()
        self.window = window
    }


}

UINavigationControllerクラスのrootViewControllerイニシャライザーにViewContorollerを渡します!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?