AppDelegate 中didFinishLaunchingWithOptions方法创建一个导航view

    ZBMainViewController *main=[[ZBMainViewController alloc] init];

    

    ZBBaseController *navigationcontroller=[[ZBBaseController alloc] initWithRootViewController:main];

 

 

    self.window.rootViewController=navigationcontroller;

转载于:https://www.cnblogs.com/zhibin/p/4114516.html

在 `AppDelegate` 也可以使用 `UINavigationController` 进行页面的跳转,但是这不是一个好的编程实践,因为 `AppDelegate` 主要负责应用程序的生命周期和应用级别的事件处理,不应该直接处理视图控制器的跳转逻辑。 如果需要在 `AppDelegate` 进行页面跳转,可以通过获取 `UIWindow` 的 `rootViewController` 属性来获取当前的根视图控制器,然后进行跳转。例如: ```objective-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 创建 UIWindow 实例 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; // 创建根视图控制器 UIViewController *rootViewController = [[UIViewController alloc] init]; rootViewController.view.backgroundColor = [UIColor whiteColor]; // 创建 UINavigationController 实例,并设置根视图控制器 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; // 将 UINavigationController 实例设置为 UIWindow 的根视图控制器 self.window.rootViewController = navigationController; // 显示窗口 [self.window makeKeyAndVisible]; // 在需要的地方进行页面跳转 UIViewController *targetViewController = [[UIViewController alloc] init]; [navigationController pushViewController:targetViewController animated:YES]; return YES; } ``` 这样做虽然可以实现页面的跳转,但是建议还是在视图控制器进行页面跳转,这样代码更加清晰,也符合 MVC 设计模式的思想。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值