单击时,NavigationLink不起作用。我正在尝试将数据从主视图传递到详细信息视图

时间:2019-10-01 03:04:39

标签: swiftui

我只想要图像上的链接。我不知道这是错误还是我的问题。我不知道这一点。任何想法都会受到赞赏

  • 这是我的ItemRow代码*

导入SwiftUI

struct ItemRow: View {
    static let colors: [String: Color] = ["D": .purple, "G": .blue, "N": .red,"S": .green, "V": .black]
    var item: MenuItem

    var body: some View {

        VStack {

            NavigationLink(destination: ItemDetail(item: item)) {
                Image(item.thumbnailImage)
                    .renderingMode(.original)
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width: 320, height: 200)
                    .cornerRadius(20)
                    .shadow(color: .black, radius: 5, x: 5, y: 5)

            }
            HStack() {
                Text(item.name)
                    .font(.headline)
                Text("$\(item.price)")
            }

            HStack {
                ForEach (item.restrictions, id: \.self) { restriction in
                    Text(restriction)
                        .font(.caption)
                        .fontWeight(.black)
                        .padding(5)
                        .background(Self.colors[restriction, default: .black])
                        .clipShape(Circle())
                        .foregroundColor(.white)
                }
            }
        }
    }
}


struct ItemRow_Previews: PreviewProvider {
    static var previews: some View {
        ItemRow(item: MenuItem.example)
    }
}

0 个答案:

没有答案