快速返回到根视图控制器

问题描述 投票:-1回答:1

我是新手,但是我已经实施了FCM,但是遇到了问题。当我单击通知时,它将使用以下代码加载NotificationsViewController

let sb = UIStoryboard(name: "Main", bundle: nil)
let otherVC = sb.instantiateViewController(withIdentifier: "NotificationsViewController") as! NotificationsViewController
self.window?.rootViewController = otherVC;

一旦加载NotificationsViewController,我将在后退按钮上使用以下代码将根视图重新分配回普通ViewController。

let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
let redViewController = mainStoryBoard.instantiateViewController(withIdentifier: "splashScreen") as! ViewController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = redViewController

一旦我在splashScreen上,它应该显示一个快速图像,然后使用此代码移至主仪表板。

let vw = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DashboardViewController") as! DashboardViewController
self.navigationController?.pushViewController(vw, animated: true)

我遇到的问题是,当应用程序从splashScreen加载NotificationsViewController代码时,该代码无法正常工作,它只是挂在该VC上,但是如果我在未重新分配根视图的情况下加载splashScreen,它就可以工作。

所以还有其他方法可以执行此操作吗?我只想在用户单击通知时将其带到NotificationsViewController,然后在单击后退按钮时将其返回到应用程序的主要部分。

ios swift viewcontroller
1个回答
0
投票

如果只需要显示NotificationViewController,则只需全屏显示。您可以通过vc.modalPresentationStyle = .fullScreen进行设置。然后返回主应用程序,只需关闭它即可。 :)

© www.soinside.com 2019 - 2024. All rights reserved.