70
64

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 5 years have passed since last update.

Swiftで初回起動画面を動的に切り替える

Posted at

ユーザー登録している場合はタイムラインへ遷移、ユーザー登録していない場合はサインイン画面に遷移というの実装する方法を調べていたのでメモ。

ViewcontrollerにStoryboard IDをつける

Main_storyboard.png

今回はユーザーが登録をしていない場合はユーザー登録画面に遷移する

AppDelegate.swiftにコードを追加


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
        let currentuser:String? = "Username"

        //ユーザーがいない場合サインイン画面に遷移
        if (currentuser == nil){
            //windowを生成
            self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
            //Storyboardを指定
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
       //Viewcontrollerを指定
            let initialViewController = storyboard.instantiateViewControllerWithIdentifier("Signin")
            //rootViewControllerに入れる
            self.window?.rootViewController = initialViewController
            //表示
            self.window?.makeKeyAndVisible()
        }else{
            //ユーザーがいる場合Storyboardでチェックの入っているIs Initial View Controllerに遷移する
        }
        
        return true
    }

以上です。

他にもこんな方法あるよというのがあれば是非教えて下さい!

70
64
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
70
64

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?