// Header File that provides all UI related items. #import // Forward declaration (Used when class will be defined /imported in future)@class ViewController;
// Interface for Appdelegate@interface AppDelegate : UIResponder // Property window @property (strong, nonatomic) UIWindow *window;
// Property Viewcontroller @property (strong, nonatomic) ViewController *viewController;//this marks end of interface @end
APPdelegate调用UIResponder来处理iOS事件
完成uiapplicationg的命令,提供关键应用程序事件,如启动完毕,终止,等待
在iOS设备的屏幕上用UIwindow对象来管理和协调各种视角,它就像其他加载视图的基本视图一样.通常一个应用程序只有一个窗口
UIViewController来处理屏幕流
// Imports the class Appdelegate's interfaceimport "AppDelegate.h" // Imports the viewcontroller to be loaded#import "ViewController.h" // Class definition starts here@implementation AppDelegate // Following method intimates us the application launched successfully - (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
// Override point for customization after application launch. self.viewController = [[ViewController alloc]
initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; [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.*/}- (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
此处定义UIApplication。上面定义的所有方法都是应用程序UI调动和不包含任何用户定义的方法。
UIWindow对象被分配用来保存应用程序分配对象。
UIController作为窗口初始视图控制器
调用makeKeyAndVisible能使窗口可见