gpt4 book ai didi

ios - 如何显示特定的 VC ,更像是导航到一堆 VC

转载 作者:可可西里 更新时间:2023-11-01 01:09:18 28 4
gpt4 key购买 nike

所以我在我的应用程序中实现了通用链接,当按下按钮时,我打开了我的第二个应用程序:

UIApplication.shared.open(aUrl!)

我也接到了电话:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {}

这是一个警报。

问题就像标题说的那样..我如何导航到特定的 VC,(从 FirstApp 到我用通用链接打开它的 Second),更像是映射 navigation controller stack

我写过类似的东西:

        if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MyAdsController") as? MyAdsViewController {
if let window = self.window, let rootViewController = window.rootViewController {
var currentController = rootViewController
while let presentedController = currentController.presentedViewController {
currentController = presentedController
}
currentController.present(controller, animated: true, completion: nil)
}
}

但这是一个丑陋的表示,我需要像洞导航堆栈这样的东西......

另外,如果我想用通用链接处理更多,我可以为此创建一个辅助类吗?任何建议表示赞赏。

最佳答案

您需要使用 UINavigationController.viewControllers 属性,您可以使用 setViewControllers(_:animated:) 方法或修改直接 .viewControllers 属性,其中 rootViewController 将是 viewControllersArray[0]topViewController 将是 viewControllersArray[ count-1]

此属性描述和详细信息可以在 UINavigationController 文档中找到

viewControllers

Property

The view controllers currently on the navigation stack.

声明SWIFT

var viewControllers: [UIViewController]

Discussion The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.

Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to false.

示例

    let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let firstViewController = storyboard.instantiateViewController(withIdentifier: "FirstViewController") as? FirstViewController
let secondViewController = storyboard.instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController
let thirdViewController = storyboard.instantiateViewController(withIdentifier: "ThirdViewController") as? ThirdViewController

self.navigationController?.setViewControllers([firstViewController,secondViewController,thirdViewController], animated: false)

关于ios - 如何显示特定的 VC ,更像是导航到一堆 VC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49050782/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com