在首次触碰iPhone开发设计的情况下,真是便是一头雾水,这是哪里跟哪里啊?原是做Android开发设计的我,首次创建iPhone开发设计而获得原始编码,内心那担心比我首次触碰Android的状况还需要槽糕!不用说那么多空话了,通 过编文章内容*来了解一下iPhone程序流程的生命期吧,这对全部开发进度也是十分有效的!
iPhone app 与 Android app在生命期在大致是同样,可是不一样的时Android的程序流程生命期都反映在每一个网页页面Activity上,换句话说,在开发设计Android app的情况下,大家只*须管理方法好每一个网页页面Activity的生命期,app的生命期就不用大家太操劳了!而iPhone app是严苛依照MVC实体模型开发设计出去的程序流程,“授权委托”这一定义是十分关键的,理所应当,iPhone app的生命期也是在“授权委托”上完成的,我们在创建iPhone app的最初的状态就可以见到2个文档:AppDelegate.h和AppDelegate.m!这两个文档是我刚常说的“授权委托”的库函数和完成文档!AppDelegate.m上就可以见到app的生命期所开启所有方式 !iPhone的生命期分成二种,一是程序流程的生命期,二是主视图(也就是等同于Android的Activity)的生命期!
*,详细介绍程序流程的生命期:(描述工作能力有待提高,上编码*具体)
[plain]
//初次载入,开启的方式 ,逐渐载入程序流程
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"app didFinishLaunchingWithOptions");
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
//当客户点击菜单健,程序流程舍弃激活状态
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"applicationWillResignActive");
}
//进到后台管理,进程被挂起来
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@"applicationDidEnterBackground");
}
//程序流程未完毕,点一下程序流程回到前台接待,再度获得激活状态,开启applicationDidBecomeActive方式 !
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"applicationWillEnterForeground");
}
//进行激话,能够与客户互动
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"applicationDidBecomeActive");
}
//程序流程完毕时开启
- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(@"applicationWillTerminate");
}
下边使我们看一下主视图的生命期:
[plain]
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"viewDidLoad");
}
- (void)viewDidUnload
{
[super viewDidUnload];
secondViewController = nil;
NSLog(@"viewDidUnload");
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
NSLog(@"viewWillAppear");
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
NSLog(@"viewDidAppear");
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:YES];
NSLog(@"viewDidDisappear");
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:YES];
NSLog(@"viewWillDisappear");
}
从方式名,大家都能够看得出来,主视图生命期里边大约开启的方式 。
如今大家运作一下程序流程,随后从一个主视图转换到第二个主视图,再返回一个主视图。使我们看一下,从程序流程、主视图的发生,衰落所开启的全部方式 :
[plain]
2012-05-10 11:29:13.426 iPhoneLifeCycle[877:f803] app didFinishLaunchingWithOptions
2012-05-10 11:29:13.459 iPhoneLifeCycle[877:f803] viewDidLoad
2012-05-10 11:29:13.462 iPhoneLifeCycle[877:f803] viewWillAppear
2012-05-10 11:29:13.465 iPhoneLifeCycle[877:f803] applicationDidBecomeActive
2012-05-10 11:29:13.472 iPhoneLifeCycle[877:f803] viewDidAppear
2012-05-10 11:29:15.054 iPhoneLifeCycle[877:f803] viewWillDisappear
2012-05-10 11:29:15.061 iPhoneLifeCycle[877:f803] viewDidDisappear
2012-05-10 11:29:16.476 iPhoneLifeCycle[877:f803] viewDidLoad
2012-05-10 11:29:16.478 iPhoneLifeCycle[877:f803] viewWillAppear
2012-05-10 11:29:16.483 iPhoneLifeCycle[877:f803] viewDidAppear
2012-05-10 11:29:21.790 iPhoneLifeCycle[877:f803] applicationWillResignActive
2012-05-10 11:29:21.796 iPhoneLifeCycle[877:f803] applicationDidEnterBackground