I want to navigate to HelloWorldView when "Hello" is clicked. However, if the text "Bye" is clicked, then I want to navigate to the ByeWorldView. In the past, I was able to use isActive
on the multiple NavigationLinks to get this to work, but Apple has deprecated this in iOS 16.2, so now I am back to the drawing board.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
ListView()
}
}
}
struct ListView: View {
var body: some View {
List {
RowView()
RowView()
RowView()
}
}
}
struct RowView: View {
@State var text: String = ""
var body: some View {
HStack{
Button("Bye") {
text = "bye"
}
Button("Hello") {
text = "hello"
}
NavigationLink("", value: text).opacity(0)
}
.navigationDestination(for: String.self) { string in
if(string == "hello") {
HelloWorldView()
} else {
ByeWorldView()
}
}
}
}
struct HelloWorldView: View {
var body: some View {
Text("Hello, World!")
}
}
struct ByeWorldView: View {
var body: some View {
Text("Bye, World!")
}
}