Iphone 如何更改rootviewcontroller
我想在authenticationViewController之后更改rootViewControllerIphone 如何更改rootviewcontroller,iphone,ios,ios5,Iphone,Ios,Ios5,我想在authenticationViewController之后更改rootViewController -(IBAction)LoginButtonPushed:(id)sender { if ([(VerifyId)isEqual:@"C"]){ CondidatsViewController *condidatsViewController = [[[CondidatsViewController alloc]initWithNibName:@"Condidats
-(IBAction)LoginButtonPushed:(id)sender {
if ([(VerifyId)isEqual:@"C"]){
CondidatsViewController *condidatsViewController = [[[CondidatsViewController alloc]initWithNibName:@"CondidatsViewController" bundle:nil]autorelease];
UINavigationController *navController = self.navigationController;
NSMutableArray *controllers = [[self.navigationController.viewControllers mutableCopy] autorelease];
[controllers removeLastObject];
navController.viewControllers = controllers;
[navController pushViewController:condidatsViewController animated: YES];
} else {
RecruteursViewController *recruteursViewController = [[[RecruteursViewController alloc]initWithNibName:@"RecruteursViewController" bundle:nil]autorelease];
UINavigationController *navController = self.navigationController;
NSMutableArray *controllers = [[self.navigationController.viewControllers mutableCopy] autorelease];
[controllers removeLastObject];
navController.viewControllers = controllers;
[navController pushViewController:recruteursViewController animated: YES];
}
}
此代码是当我按下登录按钮时,我希望CondidatsViewController或RecruteursViewController将成为根视图
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
AcceuilViewController *viewController =[[[AcceuilViewController alloc]
initWithNibName:@"AcceuilViewController" bundle:nil]autorelease];
self.navController = [[[UINavigationController alloc]initWithRootViewController:viewController]
autorelease];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
}
让视图控制器比导航和身份验证视图控制器高一级怎么样?此视图控制器可以检查有效会话,并将任何适当的视图推送到堆栈顶部。尝试更改根视图控制器似乎是不明智的 编辑:更多详细信息 您有一个根视图控制器,它没有像大多数其他视图控制器那样绑定视图。您将此类设置为应用程序委托中的根视图控制器 App Delegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
RootViewController *rootViewController = [[RootViewController alloc] init];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
在根视图控制器中,您可以确定是否有有效的会话。基于此,可以渲染适当的视图
RootViewController.m
@interface RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad
{
[super viewDidLoad];
BOOL isUserAuthenticated = [MyClasskToFigureOutIfUserIsAuthenticated isUserAuthenticated];
if(isUserAuthenticated == NO) {
AuthViewController *vcAuth = [[AuthViewController alloc] init];
[self addChildViewController:vcAuth];
[self.view addSubView:vcAuth.view];
} else {
//they are authenticated so push your other view controller.
}
}
@end
这相当粗糙,但它应该为您指出正确的方向。在导航和身份验证视图控制器之上设置一个视图控制器怎么样?此视图控制器可以检查有效会话,并将任何适当的视图推送到堆栈顶部。尝试更改根视图控制器似乎是不明智的 编辑:更多详细信息 您有一个根视图控制器,它没有像大多数其他视图控制器那样绑定视图。您将此类设置为应用程序委托中的根视图控制器 App Delegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
RootViewController *rootViewController = [[RootViewController alloc] init];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
在根视图控制器中,您可以确定是否有有效的会话。基于此,可以渲染适当的视图
RootViewController.m
@interface RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad
{
[super viewDidLoad];
BOOL isUserAuthenticated = [MyClasskToFigureOutIfUserIsAuthenticated isUserAuthenticated];
if(isUserAuthenticated == NO) {
AuthViewController *vcAuth = [[AuthViewController alloc] init];
[self addChildViewController:vcAuth];
[self.view addSubView:vcAuth.view];
} else {
//they are authenticated so push your other view controller.
}
}
@end
这相当粗糙,但它应该为您指明了正确的方向。您可以尝试UINavigationController的以下方法,其中包含一组新的所需视图控制器,如
[self.navigationController setViewControllers:@[newRootViewControllerInstance, secondVCInstanceIfRequired, thirdVC-and-so-on....] animated:NO];
它会成功的 您可以使用一个新的所需视图控制器数组来尝试UINavigationController的以下方法,如
[self.navigationController setViewControllers:@[newRootViewControllerInstance, secondVCInstanceIfRequired, thirdVC-and-so-on....] animated:NO];
它会成功的 你能再解释一下吗?你能再解释一下吗?