Cat learning iOS (22) UI Uiapplicationdelegate and UIWindow

Source: Internet
Author: User

Cat Share, must boutique

Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents

Uiapplicationdelegate

Each new project, there is a "appdelegate" word of the class, it is the agent of UIApplication

Nyappdelegate has complied with the Uiapplicationdelegate protocol by default and is already a proxy for uiapplication

The relationship between UIApplication and delegate

iOS program start-up process

The complete process of program initiation
1.main function

2.UIApplicationMain
* Create UIApplication objects
* Create a UIApplication delegate object

3.delegate object starts processing (listening) system events (no storyboard)
* When the program is started, the agent's application:didfinishlaunchingwithoptions is called: method
* Create UIWindow in application:didfinishlaunchingwithoptions:
* Create and set UIWindow Rootviewcontroller
* Display window

3. According to Info.plist to obtain the most important storyboard file name, load the main storyboard (with storyboard)
* Create UIWindow
* Create and set UIWindow Rootviewcontroller
* Display window

Uiapplicationmain parameters

A uiapplicationmain function is executed in the main function.

int main(intchar * argv[]){    @autoreleasepool {        returnclass]));    }}
intUIApplicationMain(intargc,char*argv[],NSString*principalClassName*delegateClassName);
argc、argv:直接传递给UIApplicationMain进?相关处理即可principalClassName:指定应?用程序类名(app的象征),该类必须是UIApplication(或子类)。如果为nil,则用UIApplication类作为默认值
The execution process of uiapplicationmain function

The Uiapplicationmain function creates a UIApplication object based on Principalclassname, creates a delegate object from the Delegateclassname, The delegate object is assigned to the delegate property in the UIApplication object, and then the main Runloop (event loop) of the program is established, and the processing of the in-line event is processed (first after the program is finished). The Uiapplicationmain function returns when the delegate object's application:didfinishlaunchingwithoptions:) program exits normally.

UIWindow

UIWindow is a special kind of uiview, usually only one uiwindow in the app.

After the iOS program starts, the first view control created is UIWindow, then the controller's view is created, the controller's view is added to the UIWindow, and the controller's view is displayed on the screen.

An iOS program can be displayed on the screen completely because it has uiwindow.

Also said, no UIWindow, can not see any UI interface?

Add UIView to UIWindow in two common ways

The view is added directly to the UIWindow, but the view corresponding Uiviewcontroller is not ignored

-(void)addSubview:(UIView*)view;

Automatically add Rootviewcontroller view to UIWindow, responsible for managing Rootviewcontroller's life cycle

@property(nonatomic,retain)UIViewController*rootViewController;
UIWindow Common methods
 -(void)makeKeyWindow;// 让当前UIWindow变成keyWindow(主窗口) -(void)makeKeyAndVisible;// 让当前UIWindow变成keyWindow,并显示出来
UIWindow's acquisition

A list of UIWindow that opens in this app so you can touch any UIView object in your app (the keyboard that pops up in a new UIWindow)

[UIApplicationsharedApplication].windows

To receive the UIWindow of the keyboard and non-touch message events, and only one uiwindow at a time in the program is Keywindow. If a text box inside a UIWindow cannot be lost, it may be because this uiwindow is not Keywindow

[UIApplicationsharedApplication].keyWindow

Get the UIWindow where a uiview is located

view.window
Iv. Object Relationship Diagram

PS: New iOS Exchange Learning Group: 304570962 can add cat qq:1764541256 or Znycat Let's study hard together.
Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents

Cat learns iOS (22) UI Uiapplicationdelegate and UIWindow

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.