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

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

问题描述

我在 AppDelegate.swift 中有以下代码来为 iOS 应用程序设置根视图控制器.但它不起作用.它遵循 Target 结构(在 General 选项卡下定义)并忽略此代码.

(Xcode 11、Swift 5.1、iOS 13)

class AppDelegate: UIResponder, UIApplicationDelegate {变量窗口:UIWindow?func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) ->布尔{window = UIWindow(frame: UIScreen.main.bounds)守卫让 rootVC = UIViewController() else {打印(未找到根 VC")返回真}让 rootNC = UINavigationController(rootViewController: rootVC)window?.rootViewController = rootNCwindow?.makeKeyAndVisible()返回真}}

无法理解问题出在哪里.

我也尝试了以下参考资料,但没有成功:

  • 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)

    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:

    解决方案

    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天全站免登陆