0

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

Patari
  • 1
  • That doesn't seem like a `NavigationLink` by SwiftUI definition, that is more of a custom `TabView` – lorem ipsum Sep 24 '22 at 00:40
  • You should not have a ForEach, you need current ticker index, then in bar just use index of previous/next ticket in navigation links. – Ptit Xav Sep 24 '22 at 16:04

0 Answers0