Wednesday, June 10, 2026
HomeiOS Developmentios - SwiftUI navigationLink isActivie not working

ios – SwiftUI navigationLink isActivie not working

[ad_1]

My view hierarchy right here is view1 -> view2 -> view3.

I take advantage of NavigationLink in view1 to open view2 and use Binding to move a price to isActivie, then move this worth to view3, and when view3 is finished, change the worth handed to false and shut view3 routinely.

However the result’s that it stays in view2. Then the worth handed in is the same as false

My intention is to come back again from view3 and return on to view1

Right here is my code.


// view 1 
@State personal var detailViewIsShow: Bool = false

var physique some: View {
    ForEach(boughtItems) { merchandise in
            NavigationLink(
                vacation spot: ItemDetailView(merchandise: merchandise, detailViewIsShow: $detailViewIsShow),
                isActive: $detailViewIsShow
            ) {
                ItemCellView(merchandise: merchandise)
            }
            .isDetailLink(false)
        }
}

// view 2
@Binding var detailViewIsShow: Bool
@State var itemEditorViewIsShow: Bool = false

var physique: some View {
        ZStack(alignment: .backside) {
            NavigationLink(
                vacation spot: ItemEditorView(merchandise: merchandise, detailViewIsShow: $detailViewIsShow),
                isActive: self.$itemEditorViewIsShow
            ) {
                EmptyView()
            }
            .isDetailLink(false)
        }
        .padding(.horizontal, 16)
        .navigationBarTitleDisplayMode(.inline)
        .navigationBarBackButtonHidden(true)
        .toolbar {
            ToolbarItem(placement: .navigationBarTrailing) {
                Button(motion: {
                    self.itemEditorViewIsShow = true
                }, label: {
                    Picture(systemName: "sq..and.pencil")
                        .body(width: 24, peak: 24)
                })
            }
        }
    }

// view 3
@Binding var detailViewIsShow: Bool

struct physique: some View {
someView()
.confirmationDialog("", isPresented: $isShowDeleteAlert) {
            Button("delete", function: .damaging) {
                merchandise!.delete(context: context)
                self.detailViewIsShow = false
                presentationMode.wrappedValue.dismiss()
            }
        }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments