I have tried to build an app by LBTA, and the author is using this method of NavigationLink:
var body: some View {
NavigationView {
VStack{
customNavBar
messagesView
NavigationLink("", isActive: $shouldNavigateToChatLogView){
Text("Chat Log View")
}
}
.overlay(newMessageButton, alignment: .bottom)
}.navigationBarHidden(true)
}
but this method is deprecated in IOS 16, which I use and I am trying to make it by new method
NavigationLink(_:value:)
, but I dont understand how to do it correctly to code work.
This is how I have tried to do this:
var body: some View {
NavigationStack {
VStack{
customNavBar
messagesView
NavigationLink(value: shouldNavigateToChatLogView){
Text("Chat Log View")
}
}
.overlay(newMessageButton, alignment: .bottom)
}.navigationBarHidden(true)
}
Code has compiled, but NavigationLink hasn't worked anymore.
I used to search this in Apple's SwuftUI migration website, and in stackowerflow also, but I just don't undersand how it works. Thanks
CodePudding user response:
You are missing .navigationDestination
:
var body: some View {
NavigationStack {
VStack{
customNavBar
messagesView
NavigationLink(value: shouldNavigateToChatLogView){
Text("Chat Log View")
}
.navigationDestination(for: ChatLog.self) { log in
ChatLogView(log: log)
}
}
.overlay(newMessageButton, alignment: .bottom)
}.navigationBarHidden(true)
}
Assuming you have a ChatLogView
that takes a ChatLog
.