【问题标题】:Xcode 11. SceneDelegate func willConnectTo. Not accepting a func with PropertiesXcode 11. SceneDelegate func willConnectTo。不接受带有属性的函数
【发布时间】:2020-01-16 02:19:12
【问题描述】:

我想在 willConnectTo 中插入一个 func(configureInitialViewController())(这样我就可以在其他 ViewControllers 中调用相同的 func)

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        configureInitialViewController()

}

    func configureInitialViewController() {
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            if 1>0 {
                window.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: ViewController1)
            } else {
                window.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: ViewController2)
            }
            self.window = window
            window.makeKeyAndVisible()

        }


    }

【问题讨论】:

  • 请给我们更多细节,让我们知道问题是什么。你有错误吗?这是什么?
  • 在我看来你需要将scene 传递给你的函数

标签: swift xcode11 swift5.1 rootviewcontroller uiscenedelegate


【解决方案1】:

改变

func configureInitialViewController()

func configureInitialViewController(_ scene: UIScene)

并将scene 传递给它

【讨论】:

  • 嘿,该参数在 SceneDelegate 中起作用。但它不适用于其他 VC。例如:@IBAction func signInButonTapped(_ sender: Any, scene: UIScene) { (UIApplication.shared.delegate as!SceneDelegate).configureInitialViewController(scene)
  • “它不起作用”到底是什么意思?你有错误吗?这是什么?
  • 控制台给出了一个很长的错误。当我尝试在另一个视图控制器中调用 configureInitialViewController(_ scene: UIScene) 时发生错误。不过没关系,因为我使用了 segue 在 VC 之间移动。
猜你喜欢
  • 1970-01-01
  • 2015-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-12
  • 2015-12-20
  • 2016-04-02
  • 1970-01-01
相关资源
最近更新 更多