iOS控制器的懶加載lazyLoadController

控制器的懶加載lazyLoadController

1.正常的一次加載
  • 1.代碼
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    UIViewController *vc=[[ViewController alloc]init];

    //vc.view.backgroundColor=[UIColor redColor];
    NSLog(@"建立UIViewController控制器,控制器的view並無建立");

    //if (_view!=nil) {
    //  loadView;
    //  didLoadView;
    //}

    self.window.rootViewController=vc;

    [self.window makeKeyAndVisible];
    return YES;
}

- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"第一次使用的時候纔會去加載,並非建立UIViewController控制器的時候去加載");
}
  • 2.圖片
2.讓其提早加載
  • 1.代碼(set rootView's background)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    UIViewController *vc=[[ViewController alloc]init];

    vc.view.backgroundColor=[UIColor redColor];
    NSLog(@"建立UIViewController控制器,控制器的view並無建立");

    //if (_view!=nil) {
    //  loadView;
    //  didLoadView;
    //}

    self.window.rootViewController=vc;

    [self.window makeKeyAndVisible];
    return YES;
}
  • 2.圖片
3.github
相關文章
相關標籤/搜索