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?

iosアプリの画面遷移(NavigationStack)

Last updated at Posted at 2024-11-16

成果物

output.gif

遷移先のページを用意

最初の画面のView(デフォルトでTitleViewという名前)と同じ階層に新しいファイルでViewを定義。

NextView
import SwiftUI
struct NextView: View {
    var body: some View {
        VStack {
            Text("Welcome!")
        }
    }
}

NavigationStackの用意

最初の画面(TitleView)の中にNavigationStack構造体でリンクを貼る。
以下のようにPreviewもできるようにしておくとXcode上で確認可能。

struct TitleView: View {
    var body: some View {
            NavigationStack{
                NavigationLink(destination: NextView()){
                    Text("画面遷移")
                }
                Text("Hello, world!")
            }
            .padding()
        }
}

#Preview {
    TitleView()
}

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?