0
1

More than 1 year has passed since last update.

最も基本的なNavigationSplitViewのサンプルコード 使い方

Last updated at Posted at 2023-06-03

宣伝

アプリ作っているので入れてみてください!!
よろしくお願いいたします!!

本題

画面の移動はListの
List(selection:
Selectionと、
NavigationLink(value: 1){
NavigationLinkのValueを使って行います。

クリックされたvalueの値がselectionのバインドされている変数に入るイメージです。

では以下がサンプルコードです。

import SwiftUI
import CoreData

struct ContentView: View {

    @State var selected:Int?
    @State var selected2:Int?
    var body: some View {
        NavigationSplitView {

            List(selection: $selected){
                NavigationLink(value: 1){
                    Text("A")
                }
                NavigationLink(value: 2){
                    Text("B")
                }
                NavigationLink(value: 3){
                    Text("C")
                }
            }
        } content: {
            if let selected = selected {
               Text(String(selected))

                List(selection: $selected2){
                    NavigationLink(value: 1){
                        Text("A")
                    }
                    NavigationLink(value: 2){
                        Text("B")
                    }
                    NavigationLink(value: 3){
                        Text("C")
                    }
                }
            } else {
                Text("No Selected")
            }
        } detail: {
            Text("Hi")
            if let selected2 = selected2 {
                Text(String(selected2))
            }else{
                Text("No Selected")
            }

        }

    }


}

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