标签:
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MJAppDelegate class]));
}
}
1.main函数
2.UIApplicationMain
3(1).delegate对象开始处理(监听)系统事件(没有storyboard)
3<1>.根据Info.plist获得最主要storyboard的文件名,加载最主要的storyboard(有storyboard)
- didFinishLaunchingWithOptions:
方法中代码创建控制器//创建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//创建跟控制器
UIViewController *VC = [[UIViewController alloc] init];
//加到窗口的跟控制器中
self.window.rootViewController = VC;
//把控制器的View加到窗口中,,不加到跟控制器中也可以显示
//[self.window addSubview:rootVc.view];
//显示窗口
//[self.window makeKeyWindow];//设为主窗口
[self.window makeKeyAndVisible];//设为主窗口且显示
//self.window.hidden = NO;//只显示
- didFinishLaunchingWithOptions:
方法中代码加载storyboard的控制器 // 1.创建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// 2.加载storyboard文件,创建控制器
// name:就是storyboard文件名
// bundle:主bundle,传入nil,表示主bundle
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// 通过标识创建控制器
// UIViewController *rootVc = [storyboard instantiateViewControllerWithIdentifier:@"vc"];
// instantiateInitialViewController:加载storyboard箭头指向的控制器
UIViewController *rootVc = [storyboard instantiateInitialViewController];
// 3.设置窗口的根控制器,并且显示窗口
self.window.rootViewController = rootVc;
// 4.显示窗口
[self.window makeKeyAndVisible];
- didFinishLaunchingWithOptions:
方法中代码加载xib的控制器 // 1.创建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// 2.设置窗口的根控制器
// 通过xib去加载控制器
// <1>.首先创建一个Xib文件
// <2>.Xib文件需要拖一个View描述控制器的View
// <3>.需要把Xib上的View与控制器连线,设置Xib的File‘owner为控制器
UIViewController *rootVc = [[UIViewController alloc] initWithNibName:@"VC" bundle:nil];
self.window.rootViewController = rootVc;
// 3.显示窗口
[self.window makeKeyAndVisible];
// 程序启动完成的时候调用
// __func__:表示当前的方法在哪个类里面调用
// 程序加载完毕的时候调用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
// 当应用程序失去焦点的时候调用
- (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:.
}
// 当程序接收到内存警告的时候调用
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
// 可以在此处清空图片缓存
NSLog(@"%s",__func__);
}
标签:
原文地址:http://www.cnblogs.com/ShaoYinling/p/4631559.html