zoukankan      html  css  js  c++  java
  • ios--appDelegate切换根视图rootViewController(最常用的场合是首次启动跳至导航ViewController)

     

    转载自 http://blog.csdn.net/wanggsx918/article/details/25215183

    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];  
            } 
  • 相关阅读:
    ORACLE触发器具体解释
    秒杀多线程第四篇 一个经典的多线程同步问题
    Java中Integer类的方法
    九大排序算法再总结
    删除条目时的确认对话框
    VirtualBox安装及使用说明和虚拟机安装XP系统图文教程
    J2EE之验证码实现
    教你用笔记本破解无线路由器password
    vSphere HA状况:未知配置错误解决的方法
    HDU 2504 又见GCD
  • 原文地址:https://www.cnblogs.com/allanliu/p/4483975.html
Copyright © 2011-2022 走看看