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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM