41-50 (UIApplication and Delegate,uiapplicationmain,uiwindow, full process of program start, delay loading of controller view)

Source: Internet
Author: User

Tag: Class C tar a int width

41.UIApplication and delegate

42.UIPickerView

43.UIDatePicker

44. The complete process of program initiation

45.UIApplicationMain

46.UIWindow

47. How to create a controller

48. Delay loading of the controller view

49. Multi-Controller

Steps to use 50.UINavigationController

{

These days have been catching the project, and today finally idle down!

Today is a good day, 2014520 of the sky in space.

Then let's look at the love of our programmers!

Love is a cycle of death, and once executed it is trapped.

Falling in love with a person is a memory leak that you can never release.

When you really fall in love with someone, that's the constant limit that never changes.

A girlfriend is a private variable that only my class can call.

The lover is the pointer, must pay attention when using, otherwise will bring the huge calamity.

}

41.UIApplication and delegate

Some system events occur when the app is disturbed, and UIApplication notifies its delegate object that the delegate agent handles these system events
-(void) applicationdidreceivememorywarning: (uiapplication *) application;//app receives memory warning when calling
-(void) Applicationdidenterbackground: (uiapplication *) application;//when the app enters the background (for example, by pressing the home button)
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions;// Called when the app has finished booting
Each new project, there is a "appdelegate" word of the class, it is the agent of UIApplication
Appdelegate has complied with the Uiapplicationdelegate protocol by default and is already a proxy for uiapplication

42.UIPickerView
Common Properties for 1.UIPickerView
@property (nonatomic,assign) id<uipickerviewdatasource> DataSource; Data source (used to tell Uipickerview how many columns there are rows)
@property (nonatomic,assign) id<uipickerviewdelegate> delegate;//agent (used to tell Uipickerview what to show every 1 rows per 1 columns, Monitor the selection of Uipickerview)
@property (nonatomic) BOOL showsselectionindicator; Do you want to display the selected indicator
@property (nonatomic,readonly) Nsinteger numberofcomponents;//How many columns are there altogether?

Common methods of 2.UIPickerView
-(void) reloadallcomponents;//re-refresh all columns
-(void) Reloadcomponent: (Nsinteger) component;//re-refresh the component column
-(void) SelectRow: (Nsinteger) Row incomponent: (Nsinteger) component animated: (BOOL) animated;//actively selects the first row of the component column
-(Nsinteger) Selectedrowincomponent: (Nsinteger) component;//get the currently selected line number in column component

3. Data source Method (Uipickerviewdatasource)
-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) How many columns pickerview;//altogether
-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (Nsinteger) component;// How many lines are there in column component?

4. Proxy method (Uipickerviewdelegate
-(CGFloat) Pickerview: (Uipickerview *) Pickerview widthforcomponent: (NSInteger) component;//What is the width of column component
-(CGFloat) Pickerview: (Uipickerview *) Pickerview rowheightforcomponent: ( Nsinteger) component;//The row height of column component is how much
-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: ( Nsinteger) Row forcomponent: (nsinteger) component;//component column, row row what text
-(UIView *) Pickerview: (Uipickerview * ) Pickerview Viewforrow: (nsinteger) Row forcomponent: (Nsinteger) component Reusingview: (UIView *) view;
//Component column row rows show what view (contents)
-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) row Incomponent: (Nsinteger) component;//selected Pickerview component column row


43.UIDatePicker
1. Common Properties
@property (nonatomic) uidatepickermode datepickermode;//datepicker display mode
@property (nonatomic, retain) Nslocale *locale;//the regional language displayed
2. Monitor the selection of Uidatepicker
* Because Uidatepicker inherits from Uicontrol, so through Addtarget: ... Listening


44. The complete process of program initiation
1.main function
2.UIApplicationMain
* Create UIApplication objects
* Create a uiapplication delegate pair
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
4. 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


45.UIApplicationMain
A uiapplicationmain function is executed in the main function.
int uiapplicationmain (int argc, char *argv[], nsstring *principalclassname, NSString *delegateclassname);
ARGC, argv: direct transfer to Uiapplicationmain for related processing can be

Principalclassname: Specifies the application class name (symbol of the app), which must be uiapplication (or subclass). If nil, use the UIApplication class as the default value
Delegateclassname: Specifies the application's proxy class, which must comply with the Uiapplicationdelegate protocol

The Uiapplicationmain function creates a UIApplication object based on Principalclassname and creates a delegate object from Delegateclassname.
and assigns the delegate object to the delegate property in the UIApplication object
The application's main Runloop (the event loop) is then created, and the event is processed (the application:didfinishlaunchingwithoptions of the delegate object is called first after the program is completed: method)
The Uiapplicationmain function returns when the program exits normally

46.UIWindow
UIWindow is a special kind of uiview that usually has only one uiwindow in an 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 entirely because it has UIWindow
It says that without UIWindow, you can't see any UI interface.

There are two common ways of adding UIView to UIWindow:
-(void) Addsubview: (UIView *) view;
The view is added directly to the UIWindow, but the view corresponding Uiviewcontroller is not ignored

@property (Nonatomic,retain) Uiviewcontroller *rootviewcontroller;
Automatically add Rootviewcontroller view to UIWindow, responsible for managing the Rootviewcontroller lifecycle
Common methods
-(void) makekeywindow;//the current UIWindow to Keywindow (main window)
-(void) makekeyandvisible; Make the current UIWindow into Keywindow and show it

UIWindow's acquisition
[UIApplication sharedapplication].windows//a list of UIWindow open in this app so that it can touch any UIView object in the app
(usually input text pop-up keyboard, in a new UIWindow)

[UIApplication Sharedapplication].keywindow
UIWindow for receiving keyboard and non-touch class message events.
And only one uiwindow at a time in the program is Keywindow.
If a text box inside a UIWindow cannot enter text,
Maybe it's because this uiwindow is not keywindow.
view.window//get the UIWindow of a UIView

47. How to create a controller
1. Create with Storyboard
Load the storyboard file first (test is the file name of storyboard)
Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Test" bundle:nil];
Then initialize the controller in the storyboard
Initialize the "Initial controller" (the controller that the Arrow refers to)
Viewcontroller *MJ = [Storyboard Instantiateinitialviewcontroller];
Initialize the corresponding controller with an identity
Viewcontroller *MJ = [Storyboard instantiateviewcontrollerwithidentifier:@ "MJ"];
2. Create directly
Viewcontroller *MJ = [[Viewcontroller alloc] init];
3. Specify the Xib file to create
Viewcontroller *MJ = [[Viewcontroller alloc] initwithnibname:@ "Viewcontroller" bundle:nil];

48. Delay loading of the controller view
The view of the controller is lazily loaded: reload when used
You can use the Isviewloaded method to determine whether a Uiviewcontroller view has been loaded
The controller's view is loaded and the Viewdidload method is called

49. Multi-Controller
An iOS app rarely consists of a single controller, unless the app is incredibly simple
When there are multiple controllers in the app, we need to manage these controllers
When you have multiple view, you can use a large view to manage 1 or more small view
Controller is the same, with 1 controllers to manage the other multiple controllers
For example, use a controller A to manage 3 controllers B, C, D
Controller A is referred to as the "parent controller" of Controller B, C, D
Controller B, C, d are referred to as controller A's "sub-controller"

To facilitate the management of the Controller, iOS offers 2 more special controllers
Uinavigationcontroller
Uitabbarcontroller

Steps to use 50.UINavigationController
Initialize Uinavigationcontroller
Set the Rootviewcontroller for UIWindow to Uinavigationcontroller
Depending on the situation, add the corresponding number of sub-controllers by the push method

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.