Controller Management for iOS apps

Source: Internet
Author: User

    • Multiple ways to create a controller and view
    • Simple use of Uinavigationcontroller: Add \ Remove Sub Controller
    • Settings for Uinavigationbar content
    • The life cycle method of the Controller

Multiple ways to create a controller and view

1?? How the controller is created

-Create directly

Viewcontroller *test = [[Viewcontroller alloc] init];

-Specify the Xib file to create

Viewcontroller *test = [[Viewcontroller alloc] Initwithnibname:@ "viewcontroller" Bundle: NIL];

-Created by 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 to initialize the "initial controller" (the controller that the Arrow refers to)
Viewcontroller *test = [Storyboard Instantiateinitialviewcontroller];
Initialize the corresponding controller with an identity
Viewcontroller *MJ = [Storyboard instantiateviewcontrollerwithidentifier:@ "Test"];

2?? How the View loads (a picture of MJ's teacher is clear)

• The view of the controller is delayed loading: time to reload • Use the Isviewloaded method to determine if a uiviewcontroller view has been loaded • The controller view is loaded and the Viewdidload method is called

Second, simple use of Uinavigationcontroller: Add \ Remove Sub-controller

1?? With Uinavigationcontroller, you can easily manage multiple controllers and easily switch between controllers, typically the system comes with the "Settings" App 2?? Uinavigationcontroller Use steps-Initialize uinavigationcontroller-settings UIWindow Rootviewcontroller for uinavigationcontroller-depending on the situation , add the corresponding number of sub-controllers by the push method Third, Uinavigationbar content settings Uinavigationcontroller Save the Sub-controller in the form of a stack
@property (nonatomic,copy) nsarray *viewcontrollers; @property (nonatomic,readonly) Nsarray * Childviewcontrollers;
• Use the push method to push a controller into the stack
-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
• Use the Pop method to remove the controller from the top of the stack
-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated;
Back to the specified child controller
-(Nsarray *) Poptoviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
Back to root controller (stack bottom controller)
-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated;

Change Content

//Uinavigationitem has the following properties that affect the contents of the navigation bar//the Back button in the upper-left corner@property (nonatomic,retain) Uibarbuttonitem *Backbarbuttonitem;//the middle title view@property (nonatomic,retain) UIView *Titleview;//Middle Caption Text@property (nonatomic,copy) NSString *title;//the view in the upper-left corner@property (nonatomic,retain) Uibarbuttonitem *Leftbarbuttonitem;//uibarbuttonitem *rightbarbuttonitem View in the upper right corner@property (Nonatomic,retain) Uibarbuttonitem *rightbarbuttonitem;

Iv. life cycle of Viewcontroller

Tep1:initwithnib Viewcontroller will perform alloc, and init.

Step2:loadview here will see if its subclasses have overridden this function, and if overridden, calls the subclass, otherwise calls her own. Note that this time the view is still not loaded in the OH.

Step3:viewdidload this time the view already exists. You can add the UI controls you want to add here.

The Step4:viewwillappear view will appear on the screen.

The Step5:viewdidappear view has been successfully rendered on the screen.

The Step6:viewwilldisappear view is going to disappear.

The Step7:viewdiddisappear view disappears from the screen

Step8:viewdidunload When a memory warning occurs, this function is executed if the view is not the view that is currently being displayed. Frees the child view.

Step9:dealloc Release Viewcontroller

The life cycle of the view is STEP3_STEP8.

Controller Management for iOS apps

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.