启动屏幕出现后,Uikit自动切换到另一个VC

发布于 2025-01-22 15:10:31 字数 694 浏览 0 评论 0原文

我正在尝试在3秒后自动从Lauch屏幕切换到主屏幕。 这是入口点视图控制器中的代码

        override func viewDidAppear(_ animated: Bool) {
                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
                     let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                     let viewController = enter code heremainStoryboard.instantiateViewController(withIdentifier: "GenresNC") 
                     UIApplication.shared.windows.first?.rootViewController = screen
                     self.view.window?.makeKeyAndVisible()
                }
            }
 

线程1:exc_bad_access(代码= 2,地址= 0x16f5c7de8)

有人可以帮忙吗?

I'm trying to automatically switch from lauch screen to home screen after 3 sec.
This is code in entry point view controller

        override func viewDidAppear(_ animated: Bool) {
                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
                     let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                     let viewController = enter code heremainStoryboard.instantiateViewController(withIdentifier: "GenresNC") 
                     UIApplication.shared.windows.first?.rootViewController = screen
                     self.view.window?.makeKeyAndVisible()
                }
            }
 

It brakes at line with mainStoryboard...
Thread 1: EXC_BAD_ACCESS (code=2, address=0x16f5c7de8)

Can somebody help ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳钉梦 2025-01-29 15:10:31

AppDelegate将自动从启动屏幕更改为window rootviewController-只需将代码放置在应用程序中(应用程序:didfinishlaunchingwithoptions)方法:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    window = UIWindow(frame: UIScreen.main.bounds)
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    window?.rootViewController = mainStoryboard.instantiateViewController(withIdentifier: "GenresNC")

    window?.makeKeyAndVisible()

    return true;
}

AppDelegate will automatically change from LaunchScreen to window rootViewController - just place your code inside application(application: didFinishLaunchingWithOptions) method:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    window = UIWindow(frame: UIScreen.main.bounds)
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    window?.rootViewController = mainStoryboard.instantiateViewController(withIdentifier: "GenresNC")

    window?.makeKeyAndVisible()

    return true;
}
谁人与我共长歌 2025-01-29 15:10:31

我已经在SceneDelegate中实现了同样的事情。

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

    
    guard let _ = (scene as? UIWindowScene) else { return }
    guard let windowScene = (scene as? UIWindowScene) else { return }


    self.window = UIWindow(windowScene: windowScene)

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let rootVC: UIViewController = storyboard.instantiateViewController(identifier: "tapBarViewController")

    let rootNC = UINavigationController(rootViewController: rootVC!)
    self.window?.rootViewController = rootNC
    self.window?.makeKeyAndVisible()
    
} 

I've implement the same thing in SceneDelegate.

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

    
    guard let _ = (scene as? UIWindowScene) else { return }
    guard let windowScene = (scene as? UIWindowScene) else { return }


    self.window = UIWindow(windowScene: windowScene)

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let rootVC: UIViewController = storyboard.instantiateViewController(identifier: "tapBarViewController")

    let rootNC = UINavigationController(rootViewController: rootVC!)
    self.window?.rootViewController = rootNC
    self.window?.makeKeyAndVisible()
    
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文