13.ios Controller Management

Source: Internet
Author: User

Master


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

How to create a controller


The common ways to create controllers are as follows: Create directly from storyboard mjviewcontroller *MJ = [[Mjviewcontroller alloc] init]; Specify Xib file to create Mjviewcontroller * MJ = [[Mjviewcontroller alloc] initwithnibname:@ "Mjviewcontroller" bundle:nil];



through Storyboard Create Controller


Load the storyboard file first (Test is the file name of storyboard) Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Test" Bundle:nil] Then initialize the controller in storyboard to initialize the "initial controller" (the arrow refers to the Controller) Mjviewcontroller *MJ = [Storyboard Instantiateinitialviewcontroller]; Initialize the corresponding controller via an identity Mjviewcontroller *MJ = [Storyboard instantiateviewcontrollerwithidentifier:@ "MJ"];

The creation of the mjviewcontroller View




Controller View The lazy load


The view of the controller is delayed loading: 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


Multi-Controller


? An iOS app rarely consists of a single controller, unless the app is extremely 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
? The same is true for controllers, with 1 controllers to manage multiple other controllers
? For example, use a controller a to manage 3 controllers B,C,D Controller A is referred to as controller B,C,D , " Parent Controller " 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 controllersUinavigationcontrollerUitabbarcontroller


Uinavigationcontroller


With Uinavigationcontroller, you can easily manage multiple controllers and easily switch between controllers, typically the system's own "settings" app

Uinavigationcontroller the simple use


? Uinavigationcontroller steps to useInitialize uinavigationcontroller set the Rootviewcontroller for UIWindow to uinavigationcontroller Depending on the situation, add the corresponding number of sub-controllers by the push method

Uinavigationcontroller the child controller


? Uinavigationcontroller to 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 controllerRemove 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;


How to modify the contents of a navigation bar


The contents of the navigation bar are determined by the Navigationitem property of the stack top controller Uinavigationitem has the following properties that affect the contents of the navigation bar the back button @property (nonatomic,retain) in the upper-left corner Uibarbuttonitem *backbarbuttonitem; The middle title View @property (nonatomic,retain) UIView          *titleview; the middle caption text @property ( nonatomic,copy)   nsstring        *title; view @property (Nonatomic,retain) Uibarbuttonitem *leftbarbuttonitem in the upper-left corner; Uibarbuttonitem *rightbarbuttonitem  The upper right corner of the View @property (Nonatomic,retain) Uibarbuttonitem *rightbarbuttonitem;

Notes

1.UIWindow

* The concept of the main window

* New UIWindow


2.Uiviewcontroller

* How to create a controller

* How the Controller view is created

* lazy loading of view

* Loadview,viewdidload,viewdidunload,didreceivememorywarning


3.Uinavigationcontroller

* basic use through " settings " Demo

* Feel the role of navigation through non- storyboard Way

1 > Creating a navigation controller

2> setting the root controller for UIWindow

3> Push1 ,2 ,3 sub-controllers

4 > Explain the principle of push ( stack, the management process of the navigation controller )

5 > stack bottom, stack top controller concept

6 > How to set the contents of the navigation bar, return text settings

7> Pop method Use

8> The relationship between push and addChild,viewcontrollers and Childviewcontroller


* Feel the role of navigation through the storyboard way


4.uiviewcontroller Lifecycle approach, appdelegate life cycle approach


Controller View Load





Memory Warning Handling




Life cycle Approach



13.ios Controller Management

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.