IOS Empty Application, a view Application created with pure code

Source: Internet
Author: User

The XCode version I used is 5.


Create an ios project and select Empty Application


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + kernel/J + kernel/zMGqz + kernel + qICBtYWluLm3OxLz + PC9wPgo8cD48L3A + CjxwcmUgY2xhc3M9 "brush: java;"> # import # Import "AppDelegate. h" // The Name Of AppDelegate can be changed. I use the default one. Int main (int argc, char * argv []) {@ autoreleasepool {return UIApplicationMain (argc, argv, nil, NSStringFromClass ([AppDelegate class]);}We can see the main function that we are no longer familiar. Object-C inherits the main function feature of C. When we start the ios application, the main function is executed after the preparation is completed during the runtime.

In the above Code, except the @ autoreleasepool command, the main function has only one line of code.

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
This line of code also returns directly, so we can infer that the UIApplicationMain function executes an "endless loop", so that the application can run on this line of code and will not end immediately. This "endless loop" is similar to windows message loop.

Note that the 4th parameter of the UIApplicationMain function, NSStringFromClass ([AppDelegate class]), is a string value, that is, you can replace it with the @ "AppDelegate" constant string.

return UIApplicationMain(argc, argv, nil, @"AppDelegate" );
UIApplicationMain creates an AppDelegate instance using reflection.

For more information, see "UIApplicationMain Introduction ".


Authorization class AppDelegate


Open the Declaration file of the AppDelegate class

#import 
 
  @interface AppDelegate : UIResponder 
  
   @property (strong, nonatomic) UIWindow *window;@end
  
 
AppDelegate inherits from UIResponder and complies with the UIApplicationDelegate protocol. UIApplicationMain communicates with AppDelegate through the UIApplicationDelegate protocol.

AppDelegate has a window of the UIWindow * type.


Open the implementation file of the AppDelegate class, which contains the default implementation of the UIApplicationDelegate protocol.

The didfinishlaunchingwitexceptions implementation

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    return YES;}

We can see that the window Member of the AppDelegate instance is initialized here. Generally, the window is the first window view of the ios application.

In the code, the background color of the window is white [UIColor whiteColor], and makeKeyAndVisible makes the window visible and displayed on the screen.


Execution Process Diagram


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.