问题描述
- IOS中如何调用Rootviewcontroller?
- 我希望在ios应用中能实现查看用户是注册用户还是新用户,如果还没注册的用户,就会转到注册页面。代码如下:
if (user != register){ RegisterViewController *registerViewController = [[RegisterViewController alloc] init]; RearViewController *rearViewController = [[RearViewController alloc] init]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:registerViewController]; self.viewController = revealController; self.window.rootViewController = self.viewController; self.window makeKeyAndVisible]; }else {FrontViewController *frontViewController = [[FrontViewController alloc] init]; RearViewController *rearViewController = [[RearViewController alloc] init];UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];RevealController *revealController = [[RevealController alloc] initWithFrontViewController:navigationController rearViewController:rearViewController];self.viewController = revealController;self.window.rootViewController = self.viewController;[self.window makeKeyAndVisible];}
如果用户没注册,就会进入注册页面
但是有问题,等用户注册完了,在屏幕上方就会出现两个导航控制器。
我用下面的代码将已注册用户导入主页面:[[self navigationController] pushViewController:revealController animated:YES];
不知道问题在哪里~
解决方案
从网上搜来的,
[[UIApplication sharedApplication] keyWindow].rootViewController = revealController;
设置另一个root view controller,看看能实现不?
时间: 2025-01-19 11:46:46