gpt4 book ai didi

iphone - 如何从 AppDelegate 获取 navController。

转载 作者:可可西里 更新时间:2023-11-01 03:36:36 26 4
gpt4 key购买 nike

我想知道,如何在 iPhone 编程中从 AppDelegate = [[UIApplication sharedApplication] delegate] 获取 navController。例如,在我们引用 AppDelegate 的其他 viewController 中。

在 applicationDelegate.h 中我们有:

UINavigationController *navController;

以及 applicationDelegate.m 中的以下内容

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

[window addSubview: navController.view];
[window makeKeyAndVisible];
}

有没有办法从主窗口获取 navController:

UIWindow *mainWindow = [appDelegate window];

最佳答案

如果这个其他 UIViewController 包含在 UINavigationController 中,您可以简单地调用:

UINavigationController *navController = self.navigationController;

来自 UIViewController。

否则,您可以将 UINavigationController 设置为 AppDelegate 中的属性。

// AppDelegate.h
@property (nonatomic, strong) UINavigationController *navController;

然后访问appDelegate.navController

或者,您可以将 UINavigationController 设置为窗口的 rootViewController:

[window setRootViewController:navController];

从任何地方调用:

UINavigationController *navController = window.rootViewController;

关于iphone - 如何从 AppDelegate 获取 navController。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10039856/

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