如何更改根视图控制器

2024-02-17

I want to change the rootViewController after the authenticationViewController enter image description here

-(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 将成为 rootView

- (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;
}

您可以使用所需视图控制器的新数组尝试 UINavigationController 的以下方法,例如

    [self.navigationController setViewControllers:@[newRootViewControllerInstance, secondVCInstanceIfRequired, thirdVC-and-so-on....] animated:NO];

它会成功的;)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何更改根视图控制器 的相关文章

随机推荐