且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swift/iOS:如何将数据从AppDelegate传递到ViewController标签?

更新时间:2023-02-01 19:03:56

如果它是根,则可以执行此操作

You can do this if it's the root

if let vc = self.window?.rootViewController as? ViewController {
    vc.result.text = u
}

对于完整的解决方案,您应该使用获得最高的UIViewController 来获得最高的vc ,然后像上面一样投射

For a complete solution you should get the top most vc with Get top most UIViewController then cast it like above