【问题标题】:swiftUI NavigationLink not taking me to the correct ViewswiftUI NavigationLink 没有带我到正确的视图
【发布时间】:2020-04-30 10:49:37
【问题描述】:

我有以下:

        ScrollView(.horizontal, showsIndicators: false) {
            HStack {
                ForEach(events) { event in
                        VStack {
                            Image(event.image)
                                .resizable()
                                .aspectRatio(contentMode: .fill)
                                .frame(width: 100, height: 100)
                                .padding(55)
                            NavigationLink(destination: PostView()) {
                            Text(event.name)
                                .font(.system(.headline))
                                .padding(.bottom,20)
                            }
                        }
                        .padding()
                        .border(Color.black, width: 4)
                        .cornerRadius(10)

                }
            }
        }

但是 NavigationLink NavigationLink(destination: PostView()) { 没有带我到正确的视图?

我已经尝试将 NavigationLink 包裹在每个 VStack 周围,但这也不会将我带到视图

【问题讨论】:

    标签: swiftui swiftui-navigationlink


    【解决方案1】:

    我认为你没有使用“NavigationView”。

    NavigationView{
            ScrollView(.horizontal, showsIndicators: false) {
                HStack {
                    ForEach((1...10).reversed(), id: \.self) {_ in
                            VStack {
                                NavigationLink(destination: PostView()) {
                                Text("event.name")
                                    .font(.system(.headline))
                                    .padding(.bottom,20)
                                }
                            }
                            .padding()
                            .border(Color.black, width: 4)
                            .cornerRadius(10)
    
                    }
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 2021-01-07
      • 2020-01-16
      • 2020-10-04
      • 2023-02-26
      • 2020-07-25
      相关资源
      最近更新 更多