How to show NavigationLink as a button in SwiftUI

后端 未结 8 2067
说谎
说谎 2021-01-31 14:39

I\'ve read a lot here about navigation in SwiftUI and tried a couple of things, but nothing is working as desired.

Basically, I have a view with a list of workouts and y

8条回答
  •  逝去的感伤
    2021-01-31 15:00

    You can use NavigationLink as Button with ZStack:

    @State var tag:Int? = nil
    ZStack {
      NavigationLink(destination: MyModal(), tag: 1, selection: $tag) {
        EmptyView()
      }
    
      Button(action: {
        self.tag = 1
      }, label: {
        Text("show view tag 1")
      })
    }
    

    Hope it will help.

提交回复
热议问题