使用未解析的标识符“ PresentationButton”

时间:2019-08-10 05:37:42

标签: xcode compiler-errors swiftui

使用未解析的标识符'PresentationButton',是否为'PresentationButton'引入了新的类?

是否有人在其代码中使用了“ PresentationButton”。我想在单击图像或内容框架时打开一个视图。


PresentationButton(destination: ContentView()) {
    CourseView()
}

我确实试图在apple开发人员的网站上找到文档,但没有看到任何内容。

2 个答案:

答案 0 :(得分:2)

不推荐使用PresentationButton。如果您想展示一张纸,请使用以下内容。

struct ModalExample: View {
    @State var show = false

    var detail: ModalView {
        return ModalView()
    }

    var body: some View {
        VStack {
            Button("Present") {
                self.show = true
            }
        }
        .sheet(isPresented: $show, content: { ModalView() })
    }
}

struct ModalView : View {
    @Environment(\.presentationMode) var presentationMode

    var body: some View {
        VStack {
            Text("Modal")
            Button("Close") {
                self.presentationMode.value.dismiss()
            }
        }
    }
} 

答案 1 :(得分:0)

如果您不是模态显示视图(在这种情况下,.sheet是可行的方法),则Xcode 11 beta 5中的首选方法是使用NavigationLink

NavigationLink(destination: ContentView()) {
            Text("show ContentView")
        }
相关问题