为什么 pushViewController 在浏览动态链接后不起作用?



我正在构建一个应用程序,该应用程序可以接收Firebase的动态链接,并在单击链接后将其重定向到特定UIViewController。因此,根据我提出的这个问题,我在AppDelegate.swift中提供了将应用程序导航到UIViewController的代码,如下所示:

func goToDynamicLinkVC() { // This function is in AppDelegate.swift
let destinationStoryboard: UIStoryboard = UIStoryboard(name: "DynamicLink", bundle: nil)
let destinationVC = destinationStoryboard.instantiateViewController(withIdentifier: "DynamicLinkView") as? DynamicLinkVC
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = destinationVC
self.window?.makeKeyAndVisible()
}

在那个UIViewController我还有一个函数,如果用户按下这样的按钮,它会移动到另一个UIViewController

func routeToDynamicForm() { // This function is in DynamicLinkVC class
let destinationVC = UIStoryboard(name: "DynamicLink", bundle: nil).instantiateViewController(withIdentifier: "DynamicFormView") as! DynamicFormVC
self.navigationController?.pushViewController(destinationVC, animated: true)
}  

但奇怪的是,现在我按下了按钮,它并没有将我移动到下一个视图控制器(在本例中为DynamicFormVC(。我试图通过这样做来调试按钮是否有效:

print("button tapped")

它在调试区域显示消息,但仍然不会重定向到下一个视图控制器。那么我该怎么做才能解决这个问题呢?如果您需要更多信息,请随时询问,我会提供给您。谢谢。

我将goToDynamicLinkVC函数更改为如下所示:

func goToDynamicLinkVC() { // This function is in AppDelegate.swift
let destinationStoryboard: UIStoryboard = UIStoryboard(name: "DynamicLink", bundle: nil)
let destinationVC = destinationStoryboard.instantiateViewController(withIdentifier: "DynamicLinkView")
let navController = UINavigationController()
navController.setViewControllers([destinationVC], animated: true)
self.window?.rootViewController = navController
}

最新更新