How to show NavigationLink as a button in SwiftUI

后端 未结 8 2071
说谎
说谎 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:18

    Very similar with Pankaj Bhalala's solution but removed ZStack:

    struct ContentView: View {
        @State var selectedTag: String?
    
        var body: some View {
            Button(action: {
                self.selectedTag = "xx"
            }, label: {
                Image(systemName: "plus")
            })
            .background(
                NavigationLink(
                    destination: Text("XX"),
                    tag: "xx",
                    selection: $selectedTag,
                    label: { EmptyView() }
                )
            )
        }
    }
    

    Wait for a more concise solution without state. How about you?

提交回复
热议问题