SwiftUI Change View with Button

前端 未结 4 1865
失恋的感觉
失恋的感觉 2021-02-04 18:48

I understand there is PresentationButton and NavigationButton in order to change views in the latest SwiftUI. However I want to do a simple operation like below. When user click

4条回答
  •  终归单人心
    2021-02-04 19:06

    Try with state & .sheet

    struct ContentView: View {
        @State var showingDetail = false
    
        var body: some View {
            Button(action: {
                self.showingDetail.toggle()
            }) {
                Text("Show Detail")
            }.sheet(isPresented: $showingDetail) {
                DetailView()
            }
        }
    }
    

提交回复
热议问题