0

我正在尝试在下面的代码中使用NavigationViewNavigationLink。听说NavigationLink只在里面有效NavigationView。但是,每当我将我的嵌入ScrollView到 aNavigationView中时,scrollView 就会停止显示并且我得到一个空白区域。我不确定它背后的原因是什么。

var body: some View {
        // I tried to embed the entire VStack into NaviationView. However, it ends up showing nothing as well
            VStack(alignment: .leading) {
                Text(self.categoryName)
                    .font(.title)
                NavigationView {
                    ScrollView(.horizontal, showsIndicators: false) {
                        HStack(alignment: .top) {
                            ForEach (self.drummers) { drummer in
                                NavigationLink("Moreinfo", destination: drummerDetail(drummer: drummer))
                                aDrummer(drummer: drummer)
                                .frame(width: 300)
                                .padding(.trailing, 30)
                            }
                        }
                    }
                    .padding()
                }
            }
        
    }

4

1 回答 1

0

如果aDrummer是一个视图(如我所假设),那么请参阅下面可能的修复 - ForEach 内容应该是单个视图

ForEach (self.drummers) { drummer in
  VStack {
    NavigationLink("Moreinfo", destination: drummerDetail(drummer: drummer))
       aDrummer(drummer: drummer)
         .frame(width: 300)
         .padding(.trailing, 30)
  }
}
于 2020-09-04T03:43:27.433 回答