How to create a new toolbar navigation link on each new view and link back to previous view?

209 Views Asked by At

Need to create a new toolbar navigation link on each new view going to the next item in the array and back button going to previous item. Currently, it doesn't do that and keeps creating a new toolbar navigationlink on the same view when a new item is added.

struct ContentView: View {

var tickets = [[ticket1Dic], [ticket2Dic], etc...] 
// Dynamically created by adding new ticket dict to array
// Can also delete ticket from array

var body: some View {

    NavigationView {

        .toolbar {
            ToolBarItemGroup (placement: .bottombar){
                
                
                // Go back to previous ticket
                ForEach (tickets, id: \.self) {  
                    NavigationLink(destination: DetailView(ticket: $0)) {
                        Image(systemName: "arrowshape.turn.up.left")
                }
        
                // Goto next ticket // In next ticket view have another toolbar item going
                // to next ticket and another tool bar item going back to previous ticket
                // continue for however many tickets
                ForEach (tickets, id: \.self) { 
                    NavigationLink(destination: DetailView(ticket: $0)) {
                        Image(systemName: "arrowshape.turn.up.right")
                }   
            }
        }
    }
}

struct DetailView: View {

    @State var ticket: ticket
    
    var body: some View {
        Text(ticket)
    
    }
}

What im trying to accomplish

0

There are 0 best solutions below