1. 源代码下载链接:02-更改窗口的根控制器
Demo示例程序源代码02-更改窗口的根控制器.zip
    18.0 KB
  2. //
  3. //  MJAppDelegate.h
  4. //  02-更改窗口的根控制器
  5. //
  6. //  Created by apple on 13-12-11.
  7. //  Copyright (c) 2013itcast. All rights reserved.
  8. //

  9. #import<UIKit/UIKit.h>

  10. @interfaceMJAppDelegate : UIResponder <UIApplicationDelegate>

  11. @property(strong,nonatomic) UIWindow *window;

  12. @end
  13. // MJAppDelegate.m

    Map
  14. //
  15. //  MJAppDelegate.m
  16. //  02-更改窗口的根控制器
  17. //
  18. //  Created by apple on 13-12-11.
  19. //  Copyright (c) 2013itcast. All rights reserved.
  20. //

  21. #import"MJAppDelegate.h"

  22. #import"MJViewController.h"

  23. @implementationMJAppDelegate

  24. MJViewController *mj;

  25. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  26. {
  27.    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  28.    
  29. //    mj = ;
  30.     MJViewController *haha = [[MJViewController alloc] init];
  31.    
  32.    self.window.rootViewController = haha;
  33.    
  34.     [self.window makeKeyAndVisible];
  35.    returnYES;
  36. }

  37. - (void)applicationWillResignActive:(UIApplication *)application
  38. {
  39.    // 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.
  40.    // 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.
  41. }

  42. - (void)applicationDidEnterBackground:(UIApplication *)application
  43. {
  44.    // 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.
  45.    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  46. }

  47. - (void)applicationWillEnterForeground:(UIApplication *)application
  48. {
  49.    // 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.
  50. }

  51. - (void)applicationDidBecomeActive:(UIApplication *)application
  52. {
  53.    // 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.
  54. }

  55. - (void)applicationWillTerminate:(UIApplication *)application
  56. {
  57.    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  58. }

  59. @end
  60. // MJTwoViewController.h

    Map
  61. //
  62. //  MJTwoViewController.h
  63. //  02-更改窗口的根控制器
  64. //
  65. //  Created by apple on 13-12-11.
  66. //  Copyright (c) 2013itcast. All rights reserved.
  67. //

  68. #import<UIKit/UIKit.h>

  69. @interfaceMJTwoViewController : UIViewController

  70. @end

  71. // MJTwoViewController.m

    Map
  72. //
  73. //  MJTwoViewController.m
  74. //  02-更改窗口的根控制器
  75. //
  76. //  Created by apple on 13-12-11.
  77. //  Copyright (c) 2013itcast. All rights reserved.
  78. //

  79. #import"MJTwoViewController.h"

  80. @interfaceMJTwoViewController ()

  81. @end

  82. @implementationMJTwoViewController

  83. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  84. {
  85.    self= [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  86.    if(self) {
  87.        // Custom initialization
  88.     }
  89.    returnself;
  90. }

  91. - (void)viewDidLoad
  92. {
  93.     [superviewDidLoad];
  94.    // Do any additional setup after loading the view from its nib.
  95. }

  96. - (void)didReceiveMemoryWarning
  97. {
  98.     [superdidReceiveMemoryWarning];
  99.    // Dispose of any resources that can be recreated.
  100. }

  101. @end
  102. // MJViewController.h

    Map
  103. //
  104. //  MJViewController.h
  105. //  02-更改窗口的根控制器
  106. //
  107. //  Created by apple on 13-12-11.
  108. //  Copyright (c) 2013itcast. All rights reserved.
  109. //

  110. #import<UIKit/UIKit.h>

  111. @interfaceMJViewController : UIViewController
  112. - (IBAction)jump2;

  113. @end
  114. // MJViewController.m

    Map
  115. //
  116. //  MJViewController.m
  117. //  02-更改窗口的根控制器
  118. //
  119. //  Created by apple on 13-12-11.
  120. //  Copyright (c) 2013itcast. All rights reserved.
  121. //

  122. #import"MJViewController.h"
  123. #import"MJTwoViewController.h"

  124. @interfaceMJViewController ()

  125. @end

  126. @implementationMJViewController

  127. - (void)dealloc
  128. {
  129.     NSLog(@"MJViewController---挂了");
  130. }

  131. - (IBAction)jump2 {
  132.     MJTwoViewController *two = [[MJTwoViewController alloc] init];
  133.    //本文永久链接,转载请注明出处:http://www.cnblogs.com/ChenYilong/p/3490675.html
  134. //    [UIApplication sharedApplication].keyWindow;
  135.    
  136.    self.view.window.rootViewController = two;
  137.    
  138. //    [self presentViewController:two animated:YES completion:nil];
  139. }
  140. @end

 

https://www.evernote.com/shard/s227/sh/cfe13922-d731-4ead-ba0c-5348b08ce0a5/9f0e2c86620dbe8318df1f260bfdbb3a

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案