0

アイテムの配列を作成して、すべてにナビゲーション リンクがあるリスト ビューを作成する方法はありますか? 以下のコードを機能させて、リスト ビューにデータを入力する各アイテムが、リスト内のアイテムの説明を持つ別のビューにリンクできるようにしようとしています。事前にすべての助けに感謝します!

    import SwiftUI
    
    struct Restaurant: Identifiable {
    var id = UUID()
    var name: String
    //var destination: 
}

struct RestaurantRow: View {
    var restaurant: Restaurant

    var body: some View {
        Text("Come and eat at \(restaurant.name)")
    }
}

struct Parts: View {
    
    var body: some View {
        
        let restaurants = [Restaurant(name: "1"), Restaurant(name: "2"), Restaurant(name: "3"), Restaurant(name: "4"), Restaurant(name: "5"), Restaurant(name: "6"), Restaurant(name: "7"), Restaurant(name: "8"), Restaurant(name: "9"), Restaurant(name: "10"), Restaurant(name: "11"), Restaurant(name: "12"), Restaurant(name: "1"), Restaurant(name: "2"), Restaurant(name: "3"), Restaurant(name: "4"), Restaurant(name: "5"), Restaurant(name: "6"), Restaurant(name: "7"), Restaurant(name: "8"), Restaurant(name: "9"), Restaurant(name: "10"), Restaurant(name: "11"), Restaurant(name: "12")]

        return List(restaurants) { restaurant in
            RestaurantRow(restaurant: restaurant)
        }
        .listStyle(GroupedListStyle())
        .environment(\.horizontalSizeClass, .regular)

    }
}

struct Parts_Previews: PreviewProvider {
    static var previews: some View {
        Parts()
    }
}
4

1 に答える 1