Controller Management for IOS (23) UI, iosui

Source: Internet
Author: User

Controller Management for IOS (23) UI, iosui

CAT/CAT sharing, must be excellent

For Original Articles, please reprint them. Reprinted Please note: Yan Nai-yu's blog
Http://blog.csdn.net/u013357243? Viewmode = contents

Multiple methods for creating controllers and views

Loading controller view

Create on storyboard

1: First load the storyboard Upload File (Test is the Upload File Name of the storyboard)

UIStoryboard *storyboard = [UIStoryboardstoryboardWithName:@"Test" bundle:nil];

2: Initialize the controller in the storyboard
Initialize the "initial controller" (Controller pointed by the arrow)

NYViewController *NY = [storyboard instantiateInitialViewController];

3: Initialize the corresponding controller using the unique identifier

NYViewController *NY = [storyboardinstantiateViewControllerWithIdentifier:@”NY"];
Directly create code
NYViewController *ny = [[NYViewController alloc] init];
Specify the xib release file to create
NYViewController *ny = [[NYViewController alloc]initWithNibName:@”NYViewController" bundle:nil];
Multiple Controllers

IOS apps are rarely composed of only one controller, unless the app is extremely simple. When there are multiple controllers in the app, we need to perform volume management on these controllers, the same is true for controllers:
Use one controller to manage multiple other controllers.

For example: ⽤ A controller A manages three controllers B, C, and D. Controller A is called controller B, C, and D. The controller B, C, and D are called controllers. a's "controllers"

To facilitate the management of controllers, iOS provides two dedicated controllers.

**
➢ UINavigationController
➢ UITabBarController
**

Delayed loading of controller view:
Delayed loading of controller view: the Controller view is delayed loading: It is loaded when it is used. You can use the isViewLoaded loads method to determine whether a view of a UIViewController has been loaded. After the Controller's view is loaded, the viewDidLoad method is called.
UINavigationController

With UINavigationController, you can easily manage multiple controllers and switch between controllers. A typical example is that the built-in "Settings" of the system should be reset.

How to Use UINavigationController

1: Initialize UINavigationController
2: Set rootViewController of UIWindow to UINavigationController.
3: add the corresponding number of subcontrollers through the push controllers method according to the actual situation.

Features of UINavigationController sub-Controller

1: UINavigationController saves sub-controllers as stacks

@property(nonatomic,copy) NSArray *viewControllers; @property(nonatomic,readonly) NSArray *childViewControllers;

2: Use the push pull method to push a controller to the stack.

- (void)pushViewController:(UIViewController *)viewControlleranimated:(BOOL)animated;

3: Enable the optimize pop method to remove the controller.
Remove the Controller at the top of the stack

- (UIViewController *)popViewControllerAnimated:(BOOL)animated;

Return to the specified sub-Controller

- (NSArray *)popToViewController:(UIViewController*)viewController animated:(BOOL)animated;

Back to the root controller (stack bottom Controller)

- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
How to modify the content in the navigation bar

The content of the navigation bar is determined by the navigationItem attribute of the stack top controller. The following attributes of UINavigationItem affect the content of the navigation bar.

1: Return button in the upper left corner

@property(nonatomic,retain) UIBarButtonItem *backBarButtonItem;

2: Title view in the middle

@property(nonatomic,retain) UIView *titleView; 

3: subtitle text in the middle

@property(nonatomic,copy) NSString *title;

4: View in the upper left corner

@property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem;

5: View in the upper-right corner of UIBarButtonItem * rightBarButtonItem

@property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;
Segue

Each line on the Storyboard used by the cube root to jump to the interface is a UIStoryboardSegue object (Segue for short)

Segue attributes
Each Segue object has three attributes.
1: Unique ID

@property (nonatomic, readonly) NSString *identifier;

2: Source Controller

@property (nonatomic, readonly) id sourceViewController;

3: Target Controller

@property (nonatomic, readonly) id destinationViewController;

Segue type
Based on the execution (jump) Time of Segue, Segue can be divided into two major types:
1: automatic mode: click a control (such as a button) to automatically execute the Segue and complete the redirection of the border rule.

● Press and hold the Control key to drag the Control line directly to the target controller. For example, click "Log on" to automatically jump to the Controller on the right. If you click a Control, you do not need to make any judgment. You must jump to the next interface. We recommend that you use the "dynamic Segue"

2: Manual: You need to manually execute the eclipsegue by writing code to complete the interface jump.
Press and hold the Control key to drag the source controller to the target controller.

A unique identifier is required:

Use the perform method to execute the corresponding Segue at the right time

[Self defined mseguewithidentifier: @ "login2contacts" sender: nil]; // The Segue must be executed by the source controller. That is, the perform authentication method must be called by the source controller.

If you click a control, you need to make some judgments. That is to say, the system jumps to the next region only after the Preset conditions are met. We recommend that you use the "dynamic Segue"

So whether to determine or whether to jump directly is an important criterion for judging the type of segue.

Extends mseguewithidentifier: sender:

1: Use the detection mseguewithidentifier: Rule Method to execute a specific Segue to complete the interface plane jump.

2: complete execution process of the receivmseguewithidentifier: sender: Upload Method

[Self authentication mseguewithidentifier: @ "login2contacts" sender: nil]; // This self is the source Controller

3: locate the corresponding line in storyboard Based on identifier and create a UIStoryboardSegue object.
Configure the sourceViewController (source Controller) of the Segue object)
DestinationViewController (Traffic label Controller) of the newly created and set Segue object in rule)

4: Call the following method of sourceViewController to prepare for the jump and pass in the created Segue object.

-(Void) prepareForSegue :( UIStoryboardSegue *) segue sender: (id) sender; // This sender is the sender in which the received mseguewithidentifier: sender

5: Call the-(void) perform of the eclipsegue object. The method starts to execute the redirect operation on the Response interface.
Retrieve the UINavigationController where sourceViewController is located
Worker calls the consumer and uses the push method of UINavigationController to push destinationViewController into the stack to complete the jump.

Controller Data Transmission

Principle: Sender parameter transmission

[Self defined mseguewithidentifier: @ "login2contacts" sender: @ "jack"]; // @ "jack" refers to the following sender //-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender;

There are two main data transmission situations between controllers: downstream and reverse transmission.
Shun Chuan
Redirect direction of the Controller: A-C
Data Transmission Direction: A-C
Data transmission scheme: Get destinationViewController, that is, controller C, in the prepareforseue: sender: Scheme Method of A, and directly transmit data to Controller C.
(To obtain data in the viewDidLoad controls method of C, assign a value to the UI control on the border worker)

Reverse Transfer
Redirect of the Controller to A-C
Data transfer direction: C-"
The data transmission scheme: let A become the agent of C, call the proxy Scheme Method of A in C, and pass the data to A through the parameters of the proxy scheme method.

Extension
UITabBarController:
Similar to UINavigationController, UITabBarController can also easily manage multiple controllers and easily switch between controllers. In typical cases, QQ and other controllers are recommended.

Controller lifecycle Method

A simple figure: the methods are all in it.

Ps: new iOS communication learning group: 304570962 can be added to cat qq: 1764541256 or znycat. Let's study hard together.
Yan Nai-yu's blog
Http://blog.csdn.net/u013357243? Viewmode = contents

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.