在AppDelegate.m中有几个默认存在的函数
//
// WJJAppDelegate.m
// 课上练习
//
// Created by Snail on 15-7-20.
// Copyright (c) 2015年 Snail. All rights reserved.
//
#import "WJJAppDelegate.h"
@implementation WJJAppDelegate
//程序的入口 只允许一次
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// [[UIScreen mainScreen] bounds]]; 适应当前屏幕的大小
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//设置window的背景颜色为白色
self.window.backgroundColor = [UIColor whiteColor];
//让window执行显示
[self.window makeKeyAndVisible];
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.
}
//当前APP已经能够看到界面 进入前台
- (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
接下来,COMMAND+N 新建一个类WJJRootUIViewController 继承于UIViewController
引入头文件后,在下面这个方法这样写
#import "WJJAppDelegate.h"
#import "WJJRootViewController.h"
@implementation WJJAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//当前的window 开辟内存 并用frame初始化
//[[UIScreen mainScreen] bounds]] 适应当前屏幕大小
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[WJJRootViewController alloc] init];
//设置当前window 的背景色
self.window.backgroundColor = [UIColor cyanColor];
//让这个windo执行
[self.window makeKeyAndVisible];
return YES;
}
其他不动,我们直接到WJJRootUIViewController.m文件中
#import "WJJRootViewController.h"
@interface WJJRootViewController ()
@end
@implementation WJJRootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//此视图控制器的入口 入口只执行一次 其他的进入后台、进入前台等等是在调用下面四个周期函数
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//把背景颜色设置为红色
self.view.backgroundColor = [UIColor redColor];
}
//视图已经出现
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
}
//视图将要出现
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
//视图将要消失
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
}
//视图已经消失
- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end