LazyVStack NavigationLink 不可点击

Posted

技术标签:

【中文标题】LazyVStack NavigationLink 不可点击【英文标题】:LazyVStack NavigationLink is not clickable 【发布时间】: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

【问题讨论】:

【参考方案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

以上是关于LazyVStack NavigationLink 不可点击的主要内容,如果未能解决你的问题,请参考以下文章

SwiftUI LazyVStack 重叠图像

SwiftUI:如何在动态列表或 LazyVStack 中获取视图框架

SwiftUI 如何创建选择列表的 LazyVStack

在 SwiftUI 1 中使用 LazyVStack

LazyVStack 和 SwiftUI 的性能不佳问题

如何在另一个 NavigationLink 中有一个 NavigationLink