Custom Navigation Bar items inactive/not working in List Details view in SwiftUI

399 views Asked by At

I am looking for some help with a disabled navigation bar item in a detailed view in SwiftUI.

enter image description here

import SwiftUI

struct ContentView: View {

    //2 dimentionary lists
    var twoDimensionArray = [[1,2,3,4,5], [10,20,30,40,50], [33,55,66,77,88]]
    
    var body: some View {
        
        NavigationView{
        
            VStack{
                // Go through 2 dimensionary lists using both list and scrollview
                List {

                    ForEach(twoDimensionArray, id: \.self) { itemList in

                        VStack(alignment: .leading, spacing: 20){

                            ScrollView(.horizontal, showsIndicators: false){

                                HStack{

                                    ForEach(itemList, id: \.self) { item  in

                                        NavigationLink(destination: listDetailView()) {
                                            Text(String(item))
                                        }
                                
                                    }
                                    
                                }
                        
                             }
                            
                        }

                        }

                    }

            }
                    
        }
    }
    
}

struct listDetailView: View{
    
    var body: some View {
        
        Text("Test")
            .navigationBarTitle(Text("Manage Inspection"), displayMode: .inline)
            //The problematic navigation bar items that is inactive//
            .navigationBarItems(trailing: Button(action: {
                print("Test")
           }
           ) {
               Image(systemName: "plus.circle")
                   .font(.largeTitle)
            })

    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

The problem:

Basically, when I navigated from the parent view into a detail view, the customised navigation bar items in the detail view are somehow disabled and inactive.

I tried a number of ways however can't make it to work, the basic structure of the program is: ContentView -> NavigationView -> List -> ScrollView -> ListDetails View -> Navigation bar items (which is inactive and not working)

and the weird thing is if I changed from the parent List View into another ScrollView, then it is working fine: The working navigation bar item with scrollView

However I have to use the ListView as the parent view for this case due to another function that is dependent on the ListView.

How can I make the navigation bar trailing item active for this case?

0

There are 0 answers