变量在不应该是 NIL 时

问题描述

我今天可能工作太多了..

在这个小应用程序中,当单击按钮时,必须在 3 秒后出现一个新视图,为 hVideoURL 变量分配一个值(该值不是 NIL)。所以一个新的视图(工作表)应该出现,文本为“IS NOT NIL”..

但出于某种原因,当它显示时,我看到“哇,它为零”,这意味着变量仍然没有价值

为什么我会这样?我错过了什么?

struct ContentView: View {
    @State var hVideoURL: URL? = nil
    @State var isPaused: Bool = false

    var body: some View {
        Button("Let's Go!") {
            dispatchQueue.main.asyncAfter(deadline: .Now() + 1) {
                print("settings isPaused to TRUE")
                self.hVideoURL = URL(string: "https://firebasestorage.googleapis.com/v0/b/fitma-e3043.appspot.com/o/flamelink%2Fmedia%2F1-horizontal.mov?alt=media&token=8f7dfc0f-0261-4a78-9eb0-6154ce1d9dfe")
                
                print("[debug] hVideoURL = \(hVideoURL)")
                
                self.isPaused = true
            }
        }
        .sheet(isPresented: self.$isPaused,ondismiss: {
            self.isPaused = false
            print("resume playing main video")
            
        }) {
           detailedVideoView
        }
    }
    
    @viewbuilder
    var detailedVideoView: some View {
        if self.hVideoURL != nil {
            vstack {
                Text("IS NOT NIL")
            }
        } else {
            Text("wow,it's nil")
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)