11
15

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

#24 チュートリアル的な初回起動時のみ表示されるViewController1例

Last updated at Posted at 2020-02-08

#はじめに
個人のメモ程度の出来なのであまり参考にしないで下さい.

#環境
Xcode:11.2.1
Swift:5.1.2
2019/11

##part1
Main.storyboardsegueを選択する.

スクリーンショット 2020-02-08 午後9.17.16.png

##part2
segueを選択した状態で,Attributes inspectorIdentifierに任意の文字列を入れる.

スクリーンショット 2020-02-08 午後9.17.25.png

##part3
AppDelegate.swiftapplication(_:didFinishLaunchingWithOptions:)に4行追加する.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        //この下の4行を追加
        let ud = UserDefaults.standard
        let firstLunchKey = "firstLunch"
        let firstLunch = [firstLunchKey: true]
        ud.register(defaults: firstLunch)
        
        return true
    }

##part4
ホーム画面のViewControllerStartViewController.swiftviewDidAppear(_)に7行追加する.

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        //この下の7行を追加
        let ud = UserDefaults.standard
        let firstLunchKey = "firstLunch"
        if ud.bool(forKey: firstLunchKey) {
            ud.set(false, forKey: firstLunchKey)
            ud.synchronize()
            self.performSegue(withIdentifier: "toAboutApp", sender: nil)
        }
}

##part5
チュートリアル画面のViewControllerAboutAppViewController.swiftの「閉じる」ボタンのアクションにに1行追加する.

@IBAction func toback(_ sender: UIButton) {

        //この下の1行を追加
        self.dismiss(animated: true, completion: nil)
}
11
15
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
11
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?