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?

SwiftUIのNavigationStackを簡単に説明してみた!

Posted at

本記事では、NavigationStack の基本的な使い方を簡単に説明してみました!

NavigationStackとは?

NavigationStack は、画面の遷移を階層構造で管理する新しいナビゲーションの仕組みです。

NavigationStack {
    List {
        NavigationLink("詳細へ", value: "詳細画面")
    }
    .navigationDestination(for: String.self) { value in
        Text("遷移先: \(value)")
    }
}

NavigationStackの基本構造

  1. NavigationStack { ... }
    ナビゲーションの起点になるビューです。

  2. NavigationLink
    リンクをタップすると遷移します。遷移先の情報(データ)を value として渡します。

  3. navigationDestination(for:_: )
    NavigationLink で渡された型に応じて、遷移先の画面を定義します。

まとめ

  • NavigationStack は NavigationView の後継として、より柔軟で安全なナビゲーションを提供

  • value と navigationDestination(for:) の組み合わせで、データ駆動の遷移が可能に

ぜひこの記事を参考にNavigationStackを使ってみてください!👍

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?