相关疑难解决方法(0)

SwiftUI @State 和 .sheet() ios13 与 ios14

您好,我在这里遇到了一个问题,在 ios13 或 ios14 上运行时,我的 .sheet() 视图之间没有一致的行为

我有这样的看法:

@State private var label: String = "" 
@State private var sheetDisplayed = false
///Some code
var body: some View {
   VStack {
      Button(action: {
         self.label = "A label"
         self.isDisplayed = true
      }) {
           Text("test")
       }
   }.sheet(isPresented: $sheetDisplayed, onDismiss: {
        self.label = ""
    }) {
        Text(self.label)
       }
 }
Run Code Online (Sandbox Code Playgroud)

在 ios 13 上,这项工作按预期进行 btn 单击 -> 设置标签 -> 调用表 -> 在文本视图中显示“A 标签”。

在 ios14 上,我在工作表关闭时在 self.label 中得到一个空字符串,因此它不显示任何内容。

我错过了什么吗?这是 iOS 14 的错误还是我在 ios13 上弄错了并得到了纠正。

PS:我有几个其他变量在我简化的闭包中传递。

ios13 swiftui ios14

9
推荐指数
1
解决办法
1511
查看次数

标签 统计

ios13 ×1

ios14 ×1

swiftui ×1