A brief talk on iOS pure Code control Uiviewcontroller View Controller jump interface of several methods

Source: Internet
Author: User

One, the most common view controller Uiviewcontoller

A normal view controller generally only the function of modal jump (ipad I do not understand, except that this is only the iphone), this method is available for all view controller objects, and to achieve this function, there are two ways.

1, through Method-(void) Presentviewcontroller: (Uiviewcontroller *) viewcontrollertopresent animated: (BOOL) Flag completion: ( void (^) (void)) Completion jump

Believe that many people have used this method, he is a member method for all view controller objects. Most of the time, this member method can be used normally, but some times may use failure, the general reason for failure is that the same view controller, at the same time, can only present an additional view controller, if the current VC has present, again Present a VC, will be prompted to fail, the specific failure hint in the log inside, I forgot to say, if you want to continue to present, it must be the original present controller dismiss.

Speaking of which, we're going to extend the controller's two. Two read-only properties that may be unnoticed by many people: Presentedviewcontroller and Presentingviewcontroller, They are present controllers and controllers that are being presenting, respectively. For example, controllers A and B,[a Presentviewcontroller B Animated:yes Completion:nil]; So a relative to B is presentingviewcontroller,b relative to a is presentedviewcontroller, that is the time

B.presentingviewcontroller = A;

A.presentedviewcontroller = B;

These two properties, in some cases, are very convenient to use. For example, now there is a C interface, C interface is displayed, there may be two cases, one is modal out, the other is push out, this time can be through the current interface object Presentingviewcontroller properties to determine exactly what kind of situation, If it is nil, it means that the Uinavigationcontroller object is push over, if not the modal come over.

2, through Method -(void) Performseguewithidentifier: (NSString *) identifier sender: (ID) sender Jump

If the code is to be used this way, first create a Uistoryboardsegue object and give the corresponding value initialization. What are the methods and properties of the Uistoryboardsegue class, and to see the official documentation, I don't have much to say here.

Uistoryboardsegue object, provides a jump source interface, jump to the purpose of the interface, and a identifier that is above the identifier, I believe so that everyone knows what this class is.

But I did not use the code so write, generally use this method to jump, I was in the storyboard directly according to the identifier to write, This is what we write in the properties of the lines (i.e., uistoryboardsegue) that are drawn between the different interfaces in storyboard.

This method also supports Uinavigationcontroller's jump, but the jump mode is push, which can only be used when the current view controller is Uinavigationcontroller.

Both of these methods are returned by dismissviewcontrolleranimated to the previous interface.

Second, navigation controller Uinavigationcontroller

1, Pushviewcontroller launch a view controller

It is important to note that this method is only possible with Uinavigationcontroller and its subclasses, and the normal controller is not. So when used is usually a anavigationcontroller pushviewcontroller or Self.navigationcontroller pushviewcontroller.

2. Jump through the Performseguewithidentifier method described above and say nothing more.

    

Since Uinavigationcontroller is a container for a view controller, he may have a lot of controllers in it, so the return time can be divided into several situations.

A: Pop up the currently displayed interface, that is, return to the previous interface, Popviewcontroller (Note that this method does not work when the current interface is the root node).

B: Return to the root junction of the controller, Poptorootviewcontroller.

C: Jump to an interface in the middle of this view controller. Poptoviewcontroller. In this way, you need to know which interface to jump to, get the interface to jump to have a lot of ways, I generally traverse uinavigationcontroller viewcontrollers array, Use the Iskindofclass method to get a controller object to jump again.

Third, Uitabbarcontroller

Tabbar Controller, I believe that we also use a lot, generally as the root interface view controller of the app. In fact, instead of Uitabbarcontroller interface jump, rather than the interface switch, Because Uitabbarcontroller interface jump is actually uitabbarcontroller viewcontrollers array of several interface switch. As long as the Uitabbarcontroller viewcontrollers array is set up, the switching of slices is basically nothing to do with us.

Four, add one point: Through the sub-interface to achieve the same controller interface switch.

We develop, you may encounter a more complex interface, to do multiple interface switching, if you put these interface switch all in the interface, the controller code is very bloated do not say, control is also more troublesome, this time I recommend using different controllers to represent different interfaces, These interfaces are then added to the controller's sub-controller via Addchildviewcontroller, and then switched through the system-provided method, as you can see from the official documentation.

This method is usually used in conjunction with Uisegmentcontroller.

PS: I contact iOS time is not very long, write a blog is to share with you, another is to promote their own progress, so insufficient and wrong place, welcome everyone advice and shoot bricks, but please do not spray people.

A brief talk on iOS pure Code control Uiviewcontroller View Controller jump interface of several methods

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.