0
votes

I am trying to use NavigationView and NavigationLink in my code below. I heard that NavigationLink only works inside NavigationView. However, whenever I embed my ScrollView into a NavigationView, the scrollView stop showing up and I get a blank space. I am not sure what is the reason behind it.

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()
                }
            }
        
    }

1

1 Answers

0
votes

If aDrummer is-a View (as I assume) then see below possible fix - ForEach content should be single view

ForEach (self.drummers) { drummer in
  VStack {
    NavigationLink("Moreinfo", destination: drummerDetail(drummer: drummer))
       aDrummer(drummer: drummer)
         .frame(width: 300)
         .padding(.trailing, 30)
  }
}