iOS 13:Swift-'以编程方式设置应用程序根视图控制器'不起作用 [英] iOS 13: Swift - 'Set application root view controller programmatically' does not work

查看:431
本文介绍了iOS 13:Swift-'以编程方式设置应用程序根视图控制器'不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppDelegate.swift中有以下代码来为iOS应用程序设置根视图控制器.但这是行不通的.它遵循目标"结构(在常规"选项卡下定义),并且忽略此代码.

I have following code in my AppDelegate.swift to setup root view controller for an iOS application. But it does not work. It follows Target structure (defined under General tab) and ignores this code.

(Xcode 11,Swift 5.1,iOS 13)

(Xcode 11, Swift 5.1, iOS 13)

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        window = UIWindow(frame: UIScreen.main.bounds)
        guard let rootVC = UIViewController() else {
            print("Root VC not found")
            return true
        }
        let rootNC = UINavigationController(rootViewController: rootVC)
        window?.rootViewController = rootNC
        window?.makeKeyAndVisible()

        return true
    }
}

无法了解问题出在哪里.

Unable to understand where is the issue.

我也尝试了以下参考文献,但没有运气:

I tried following references also but no luck:

  • Swift ios set a new root view controller
  • Root View Controller Swift
  • iOS: Root Controller Navigation

推荐答案

要从Xcode 11创建的项目中为SwiftUI支持的方法选择先前的方法,请按照以下步骤操作.

To choose a previous approach to the one supported by SwiftUI, from a project created in Xcode 11, you can follow these steps.

这篇关于iOS 13:Swift-'以编程方式设置应用程序根视图控制器'不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆