- 源代码下载链接:
02-更改窗口的根控制器.zip
18.0 KB -
// MJAppDelegate.h
- //
- // MJAppDelegate.h
- // 02-更改窗口的根控制器
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJAppDelegate : UIResponder <UIApplicationDelegate>
- @property(strong,nonatomic) UIWindow *window;
- @end
-
// MJAppDelegate.m
Map - //
- // MJAppDelegate.m
- // 02-更改窗口的根控制器
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJAppDelegate.h"
- #import"MJViewController.h"
- @implementationMJAppDelegate
- MJViewController *mj;
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // mj = ;
- MJViewController *haha = [[MJViewController alloc] init];
- self.window.rootViewController = haha;
- [self.window makeKeyAndVisible];
- returnYES;
- }
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
- }
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- }
- @end
-
// MJTwoViewController.h
Map - //
- // MJTwoViewController.h
- // 02-更改窗口的根控制器
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJTwoViewController : UIViewController
- @end
-
// MJTwoViewController.m
Map - //
- // MJTwoViewController.m
- // 02-更改窗口的根控制器
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJTwoViewController.h"
- @interfaceMJTwoViewController ()
- @end
- @implementationMJTwoViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self= [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if(self) {
- // Custom initialization
- }
- returnself;
- }
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- // Do any additional setup after loading the view from its nib.
- }
- - (void)didReceiveMemoryWarning
- {
- [superdidReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
-
// MJViewController.h
Map - //
- // MJViewController.h
- // 02-更改窗口的根控制器
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJViewController : UIViewController
- - (IBAction)jump2;
- @end
-
// MJViewController.m
Map - //
- // MJViewController.m
- // 02-更改窗口的根控制器
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJViewController.h"
- #import"MJTwoViewController.h"
- @interfaceMJViewController ()
- @end
- @implementationMJViewController
- - (void)dealloc
- {
- NSLog(@"MJViewController---挂了");
- }
- - (IBAction)jump2 {
- MJTwoViewController *two = [[MJTwoViewController alloc] init];
- //本文永久链接,转载请注明出处:http://www.cnblogs.com/ChenYilong/p/3490675.html
- // [UIApplication sharedApplication].keyWindow;
- self.view.window.rootViewController = two;
- // [self presentViewController:two animated:YES completion:nil];
- }
- @end