Good morning everyone,
I am new when it comes to NavigationSplitView. I'm not sure when you want to put a .navigationDestination
. Here is my scenario. I have a view that has a NavigationSplitView in it. Like this:
NavigationSplitView(columnVisibility: $visibility) {
VStack(alignment: .center) {
// This shows a segmented control to user so they can choose between
// completed and scheduled programs
ChooseWhichProgramsToView(
whichProgramsToShowChoice: $showCompletedOrScheduledProgramsChoice,
currentSelectedProgram: $currentSelectedProgram,
sortProgramItemsByNameDateTypeChoice: $sortProgramItemsByDateChoice,
itemCount: countOfPrograms()
)
// Where we see the list of programs associated as either scheduled
// or completed.
ShowProgramsContainerView(
currentSelectedProgram: $currentSelectedProgram,
whichProgramsToShowChoice: $showCompletedOrScheduledProgramsChoice,
sortProgramItemsByNameDateTypeChoice: $sortProgramItemsByDateChoice,
searchTerm: $searchTerm
)
}
.navigationTitle(showCompletedOrScheduledProgramsChoice == 0 ? .scheduledProgramsTitle : showCompletedOrScheduledProgramsChoice == 1 ? .completedProgramsTitle : .allProgramsTitle)
.navigationBarTitleDisplayMode(.inline)
.searchable(text: $searchTerm, placement: .navigationBarDrawer(displayMode: .always), prompt: Text(.searchByProgramName))
.toolbar {
returnTrailingNavBarItems()
}
.toastView(toast: $toast)
} detail: {
if let program = currentSelectedProgram {
withAnimation {
DetailOfSelectedProgramView(program: program)
}
} else {
withAnimation {
NoProgramsSelectedView()
}
}
}
.navigationSplitViewStyle(.balanced)
.onDisappear {
currentSelectedProgram = nil
}
The ShowProgramsContainerView
is this
VStack {
if whichProgramsToShowChoice == 0 {
// Inside here we are working with scheduled programs
if dm.getAllProgramsByStatus(byNameDateType: sortProgramItemsByNameDateTypeChoice,
programStatus: Status.scheduled).isEmpty {
} else if dm.getAllProgramsByStatus(byNameDateType: sortProgramItemsByNameDateTypeChoice,
} else {
List(selection: withAnimation { $currentSelectedProgram } ) {
ForEach(dm.getAllProgramsByStatus(byNameDateType: sortProgramItemsByNameDateTypeChoice,
programStatus: Status.scheduled).filter {
searchTerm.appearsIn($0.name) || searchTerm.appearsIn($0.date.dateText(style: .medium))
}, id: \.self) { program in
NavigationLink(value: program) {
ListOfProgramsRowView(program: program)
}
}
.onDelete(perform: deleteAllScheduledPrograms)
}
.tint(Color.listRowHightlight)
.listStyle(.plain)
}
} else if whichProgramsToShowChoice == 1 {
// I took the code out here its the same as above. Shows the list of programs
} else {
// I took the code out here its the same as above. Shows the list of programs
}
}
}
As you can see I have a list with with a binding to the currentSelectedProgram
. What I need to know is do I need to have NavigationLink(value: program)
here. I struggle with when you need to use NavigationLink
and .navigationDestination
.
If someone could shed some light on this I'd appreciate it. If I remove NavigationLink the program still navigates to the view in the detail
section.
I hope all this was clear and apologize for the length. I tried to shorten it as much as possible.
Thanks
Taz