ios 唤醒app返回根视图_ios - appDelegate切换根视图rootViewController(最常用的场合是首次启动跳至导航ViewController) - 期权论坛...

1、在appDelegate中添加一个切换的方法switchRootViewController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {

//第一次启动导航页

NSLog(@"wanggsx:第一次启动");

ViewController *appStartController = [[ViewController alloc] init];

self.window.rootViewController = appStartController;

[self.window addSubview:appStartController.view];

}

else

{

//打开选择场地界面

[self switchRootViewController];

}

[self.window makeKeyAndVisible];

return YES;

}

//切换RootViewController

- (void)switchRootViewController

{

self.window.rootViewController = nil;

ChooseModeViewController* crBrandsViewController= [[ChooseModeViewController alloc] init];

UINavigationController *brandsNavigationController = [self customControllerWithRootViewController:crBrandsViewController];

self.viewController = brandsNavigationController;

self.window.rootViewController = self.viewController;

}

2、在需要切换根视图的ViewController中调用appDelegate中的方法:

- (IBAction)gotoMainView:(id)sender {

[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];

[(AppDelegate*)[UIApplication sharedApplication].delegate switchRootViewController];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值