How can I do a Button action -> second screen.
I know that NavigationView -> NavigationLink about but I want to know how can I do the same but with Button(action {secondScreen})
thanks and bye! :D
How can I do a Button action -> second screen.
I know that NavigationView -> NavigationLink about but I want to know how can I do the same but with Button(action {secondScreen})
thanks and bye! :D
You can bind navigation link to a button to achieve what you're looking for like this
struct ContentView: View {
// MARK: - PROPERTIES
@State private var onSecondScreen: Bool = false
// MARK: - BODY
var body: some View {
NavigationView{
VStack{
// Your Button
Button {
onSecondScreen = true
} label: {
Text("Second Screen")
}
// NAVIGATION LINK
NavigationLink(isActive: $onSecondScreen) {
Text("Second Screen")
} label: {}
}//: VSTACK
}//: NAVIGATION
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}