【问题标题】:App.Delegate from ViewController to TabController Swift 5App.Delegate 从 ViewController 到 TabController Swift 5
【发布时间】:2019-10-27 06:08:43
【问题描述】:

我的代码在Swift 5 中不起作用

var myTabBar = self.storyboard?.instantiateViewController(withIdentifier: "myTabBar") as! UITabBarController
var app = UIApplication.shared.delegate as! AppDelegate
app.window?.rootViewController = myTabBar

AppDelegate 类型的值没有成员 window

【问题讨论】:

标签: ios swift


【解决方案1】:

因为在新的 Xcode 窗口中移动到了 SceneDelegate

【讨论】:

  • var myTabBar = self.storyboard?.instantiateViewController(withIdentifier: "myTabBar") as! UITabBarController 让 app = UIApplication.shared.delegate 为? SceneDelegate app?.window?.rootViewController = myTabBar
【解决方案2】:

我在这里与您会面已过半,因为我们确实需要更多关于正在发生的事情以及您想要实现的目标的详细信息。

但错误告诉您 AppDelegate 没有名为 window 的变量。您可能需要 UIApplication 对象本身,而不是它的委托。

可以试试替换

var app = UIApplication.shared.delegate as! AppDelegate
app.window?.rootViewController = myTabBar

var app = UIApplication.shared
app.keyWindow?.rootViewController = myTabBar

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    相关资源
    最近更新 更多