[置顶] 程序执行流程

时间:2022-06-05 17:06:32
#import "AppDelegate.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

//4、1、3、2

//alloc]init]方法调用之后,会去调用 initWithNibName方法;之后,回到入口类继续向下执行 ;当window.rootViewController = vc 代码h执行之后,会去调用viewDidLoad方法;之后回到入口类继续执行
FirstViewController * vc = [[FirstViewController alloc]init];
NSLog(@"1");
self.window.rootViewController = vc ;
NSLog(@"2");

return YES;
}


#import "FirstViewController.h"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
NSLog(@"4");
}
return self;
}
//先加载xib,再执行viewDidLoad ;注意视图的层次
- (void)viewDidLoad
{
[super viewDidLoad];

NSLog(@"3");
}

[置顶]        程序执行流程