0
1

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.

SwiftUIでNavigationVarとListの組み合わせ

Last updated at Posted at 2020-05-04

SwiftUIでNavigationViewSwiftUIでListの組み合わせです。

##リストを表示する

UIKitでのNavigationViewとtableViewの組み合わせをSwiftUIで行います。

スクリーンショット 2020-05-04 17.55.21.png スクリーンショット 2020-05-04 18.16.51.png

UIKitでお馴染みのNavigationVarをSwiftUIで作成します。

import SwiftUI

struct FirstView: View {
    var Array = ["あ行","か行","さ行","た行","な行","は行"]
    var body: some View {
        
        NavigationView {
            List {
                ForEach(Array, id: \.self) { i in
                    NavigationLink(destination: SecondView())  {
                        Text(i)
                    }
                }
            }
            .navigationBarTitle("遷移前")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        FirstView()
    }
}

キーとなるのはNavigationLink()で遷移先のViewを指定しているところです。

import SwiftUI

struct SecondView: View {
    var body: some View {
            Text("遷移先")
    }
}

struct SecondView_Previews: PreviewProvider {
    static var previews: some View {
        SecondView()
    }
}

ただ遷移するだけであれば上のコーデ行うことができます。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?