之前在SwiftUI (Xcode Beta 5)中/uff0c模式是这样工作的:
struct ContentView: View {
@State var modalIsPresented: Bool = false
var body: some View {
Button(action: {
self.modalIsPresented = true
}) {
Text("Show modal")
}
.sheet(isPresented: $modalIsPresented, content: {
ModalView()
})
}
}
struct ModalView: View {
@Environment(/.presentationMode) var presentationMode
var body: some View {
Button(action: {
self.presentationMode.value.dismiss()
}) {
Text("Hide modal")
}
}
}
但现在在Xcode Beta 6中/uff0c我找不到解雇模态的方法。 不再有presentationMode的value属性/uff0c其他属性似乎没有任何有用的方法我可以使用。
所以如何解雇Xcode Beta 6中的SwiftUI模式呢/uff1f
使用wrappedValue而不是value在Xcode Beta 6中会起作用/uff1a
self.presentationMode.wrappedValue.dismiss()
本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/xcode-beta-6zhongdeswiftuimoshi.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:8 月 25, 2019 at 10:23 下午