Jumps between multiple controllers

Source: Internet
Author: User

Jumps between multiple controllers

1> What is a jump between multiple controllers?

In one APP, there will be multiple controllers, and the presence of multiple controllers will present a problem with the controller's jump.

2> includes: Link jump, modal mode and Navigationcontroller/tabbarontroller mode

    • Connect Jump: The controller jumps according to the ID of the binding

Categories of connection jumps:

> Auto type: After clicking on the control, it automatically jumps to the next controller (Action–push mode)

> Manual: It needs to be done manually with the help of code.

Manual type, which refers to the drag from the source controller to the target controller. (Manual–push mode), manual type you need to set the identify tag in the storyboard segue. Manual type to invoke the method:

[Self performseguewithidentifier:id sender:nil];

The system will call:

-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender

Note: Passing data to the next controller sequence can be written in this method.

    • Modal mode This mode is the default way of the system, it is from the bottom of the system to go up, covering the original controller.

Steps to use:

1 Creating the controller to jump to

2 Jump and close

[Self Presentviewcontroller: Controller created]

[Self Dismissviewcontrolleranimated:yes]

3 sub-controllers are destroyed after DISMISSS

    • Push and Pop mode, which is used for Navigationcontroller jumps

Steps to use:

1 Creating the controller to jump to

Note: Use this method to be sure to set the root controller.

2 Jump and exit

[Self.navigationcontroller PUSHVIEWCONTROLLER:VC Animated:yes];

3 When using Uinavigationcontroller, the Uinavigationcontroller will put a navigation bar on all the target controllers, and will automatically generate an item return button on the navigation bar after the push is completed. The button can be returned directly to the controller on the previous layer.

Note: Setting the navigation bar with Uinavigationcontroller only needs to be set once, and then the derived navigation bar is the same as the root controller's navigation bar. The navigation bar is set up in the Initialize method by setting the Appearance agent object to complete

Note: Uitabbarcontroller to the controller to jump all the time to load the complete, its sub-controller is present, and will not be destroyed by jumping to other sub-controller. There are two ways to load a child controller: ADDCHILDVIEWCONTROLLER:VC (Load a sub-controller). Viewcontrollers (Load multiple sub-controllers) its return value is an array that can be loaded directly into the array and be aware that the order loaded into the array is the order in which the display is loaded into the TabBar.

3> differences in different jump modes

1 push-pop need to be used in Navigationcontroller. The way is to stack the way the controller jumps, when the stack of the new controller placed on the top of the stack. is to slide the way into the controller

-(void) Pushviewcontroller: (Uiviewcontroller *)

Viewcontroller animated: (BOOL) animated;

There are three ways to exit the >

> controller enters the time is to enter the way into the stack, that is, the new controller entered from the right side, the previous controller pushed to the left, when exiting the stack top controller directly removed. (note Tabbarcontroller does not remove the controller, just switch back and forth.)

> Remove Stack Top controller:-(Uiviewcontroller *) Popviewcontrolleranimated method

> Return to the specified sub-controller:-(Nsarray *) Popviewcontroller method

> Back to the root controller

-(Nsarray *) Poptorootviewcontroller method

2 Modal Way:

Any controller can be modal way to jump, is a universal way to jump, the default effect is to go up from the bottom up, until completely cover the above controller. The covered controller is not destroyed.

3 A push-loaded controller adds a return button to the child controller, but the modal method is not automatically added, and the return button is created on its own.

4 modal out of the controller will be the original controller completely covered, the original controller is not clickable. And since the push controller is just the push controller in Navigationcontroller.

4> Supplement

4.1 iOS provides 2 more special controllers for easy management of the controller

Uinavigationcontrolle Uitabbarcontroller.

4.1.2 usually use the Uitabbarcontroller controller as the root controller of the window, then the Uinavigationcontrolle as the root controller of the Uitabbarcontroller, and then load the required controller.

4.1.3 The root controller step of the Setup window

Generally in the appdelegate inside the set

> Initialize a window

> Setting the window's root controller as the navigation controller

> When initializing the navigation controller, it is common to follow a controller.

Characteristics of 4.1.4 Uinavigationcontrolle

Add the controller to the > stack and use the push operation to remove the controller using the pop operation.

> The first controller added at the bottom of the stack, and then add the controller on top, the direct use of pop operation, is to let the stack top controller destroyed, you can specify the controller of the pop. But be aware of the loop reference of the controller.

> Push/pop is a unique way of Uinavigationcontrolle, only Uinavigationcontrolle and its subclasses can use this method.

> Pop controller can have Popviewcontroller (return to the previous controller), Poptoviewcontroller (return to the specified controller), Poptorootviewcontroller (return to the root controller) Three kinds of. Note: To get the specified controller in the way of traversal (XXX iskindofxxx)

4.2 Uitabbarcontroller

4.2.1 Internal implementation principle: The view is managed in a parallel way, and the views tend to be relatively small, and each view added to the Uitabbarcontroller is initialized even though it is not currently displayed on the interface, it is more memory-intensive. The controller is switched by the index of the selected (click Action) by adding the controller to the child controller collection of the tag controller. The tag controller also has a collection of sub-controllers within it.

4.2.2 Implementation principle: Uitabbarcontroller is designed by Apple specifically to take advantage of the tab switch view, which has a Uitabbar control in the view controller that the user clicks Tabbar to switch views. We know there is a view inside the Uiviewcontroller, and once the Uiviewcontroller is created, the view is displayed by default, but Uitabbarcontroller itself does not display any views. If you want to display a view, you must set its Viewcontrollers property (which shows viewcontrollers[0] by default). This property is an array that maintains a child view of all Uitabbarcontroller. In order to minimize the coupling between views, all Uitabbarcontroller related headings, icons and other information are controlled by the child view, Uitabbarcontroller only as a container exists

4.3 iOS8 new Switching method Showviewcontroller

This method should be said to be the universal interface switching method, it can be based on the current attempt to determine the controller is to use the push method or the normal modal way to switch the interface. In the current interface is Navi sub-VC, if using the Showviewcontroller method, it will be push mode (can be returned by pop), and if the current interface is modal interface, you will use the modal way. So to speak, if there is no special requirements need modal interface, you only need to peremptorily in the interface switch with the Showviewcontroller method on the line, iOS SDK background basically has been processed how you jump. In addition, in the past, the navigation controller sub-VC is unable to push a new navigation controller, otherwise the operation will hang, but Showviewcontroller can do!

Jumps between multiple controllers

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.