设置rootViewController iOS 13

奥利弗·费里斯(Oliver Ferris)

升级Xcode后,我的应用程序的关键部分已停止工作。

当我的应用启动时,我运行一个函数来检查布尔标志并设置正确的rootViewController。

但是我一直用来设置它的代码现在已经停止工作

class func setLoginAsInitialViewContoller(window:UIWindow) {
    print("SET LOGIN") 
    let storyboard = UIStoryboard(name: "Login", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "LoginViewController")
    controller.modalPresentationStyle = .overFullScreen
    window.rootViewController = controller
    window.makeKeyAndVisible()
}

具体来说,当应用获得倒数第二行时,window.rootViewController = controller它会因libc++abi.dylib: terminating with uncaught exception of type NSException错误而崩溃

上面的函数在一个名为的类中Utilities.swift,我正在从内部调用该函数AppDelegate.swift,如下所示:

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var storyboard: UIStoryboard? = nil

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

        UIApplication.shared.isIdleTimerDisabled = true
        Utilities.decideInitialViewController(window: self.window!)

        return true
    }

非常感谢任何关于如何设置根控制器的解决方案或修复方法。

谢谢!

卢卡·塞法林(Luka Cefarin)

这是因为AppDelegate不再具有window属性。现在,您必须使用SceneDelegate的scene(_:willConnectTo:options:)方法来更改根视图控制器。如本例所示:

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let scene = (scene as? UIWindowScene) else { return }

        // Instantiate UIWindow with scene
        let window = UIWindow(windowScene: scene)
        // Assign window to SceneDelegate window property
        self.window = window
        // Set initial view controller from Main storyboard as root view controller of UIWindow
        self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
        // Present window to screen
        self.window?.makeKeyAndVisible()
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

设置keyWindow rootViewController在iOS8中不起作用

在Xamarin.iOS中设置RootViewController后NavigationNavigator为null

iOS-设置“ rootViewController”仅在设备上导致黑屏

嵌套设置页面在iOS13中崩溃

iOS 13设置状态栏背景色

如何为iOS 13的SF符号设置权重?

无法在iOS 13中设置标签栏阴影图像

如何以编程方式设置iOS 13字形

未将ios13中的UITextfield的PlaceholderColor设置为PlaceHolderLabel

Swift:在 IOS13+ 上设置 StatusBar 颜色(使用 statusBarManager)

如何在iOS Swift中使用Xib将UINavigationController设置为rootviewcontroller?

iOS动态更改rootViewController

目标设置为iOS 13的iOS应用未在App Store中提供较早版本

iOS的ProgressBar 13

iOS 13替代“ setAnimationCurve”

iOS 13 TLS问题

iOS 13 UIBarButtonItem字体

iOS 13上的AVAssetReferenceRestrictions

iOS 13 UISplitView问题

iOS13 UIViewController isModalInPresentation在ObjectiveC中没有设置器,因此无法设置?

如何在iOS 13中将UISegmentedControl的backgroundColor设置为白色

在 ios 13 中设置后退按钮箭头色调的正确方法是什么

iOS13共享表:共享UIImage时如何设置预览缩略图

iOS 13 应用程序的“启用多个 Windows”设置(仅限 iPhone)

无法使用外观xamarin在IOS 13+上设置导航标题颜色

崩溃 Xcode 11,iOS13 设置根视图控制器

IOS13 iPad设置因已付费的应用程序崩溃

如何在iOS 13中显示的视图控制器下方设置系统背景色

重定向到 RootViewController ios