【问题标题】:LazyVStack NavigationLink is not clickableLazyVStack NavigationLink 不可点击
【发布时间】:2021-04-13 10:20:41
【问题描述】:

我有一个LazyVStack

                        ScrollView {
                            if #available(iOS 14.0, *) {
                                LazyVStack {
                                    ForEach(searchViewModel.allUsers, id: \.uid) { user in
                                        VStack {
                                            profileCard(profileURL: user.profileURL, username: user.username, age: user.age, cardWidth: self.cardWidth, country: user.city)
                                            NavigationLink(destination: ProfileDetailedView(userData: user)) {
                                                EmptyView()
                                            }.buttonStyle(PlainButtonStyle())
                                        }.padding(.top,5)
                                    }
                                }
                            } else {
                                // Fallback on earlier versions
                            }
                        }

现在NavigationLink 不工作了?

我没有 LazyVStack 的原始代码运行良好(如下)

                       List {
                            ForEach(searchViewModel.allUsers, id: \.uid) { user in
                                VStack {
                                    profileCard(profileURL: user.profileURL, username: user.username, age: user.age, cardWidth: self.cardWidth, country: user.city)
                                    NavigationLink(destination: ProfileDetailedView(userData: user)) {
                                        EmptyView()
                                    }.buttonStyle(PlainButtonStyle())
                                }.padding(.top,5)
                            }
                        }

更新

我在视图顶部使用 NavigationView

【问题讨论】:

    标签: swift swiftui


    【解决方案1】:

    您是否在我的视图顶部使用了 NavigationView? 示例:

    NavigationView{ // -> Here
        List {
            ForEach(searchViewModel.allUsers, id: \.uid) { user in
                VStack {
                    profileCard(profileURL: user.profileURL, username: user.username, age: user.age, cardWidth: self.cardWidth, country: user.city)
                    NavigationLink(destination: ProfileDetailedView(userData: user)) {
                        EmptyView()
                    }.buttonStyle(PlainButtonStyle())
                }.padding(.top,5)
            }
        }
    }
    

    【讨论】:

    • 是的..更新了我的答案。我在视图的顶层使用 NavigationView
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-23
    相关资源
    最近更新 更多