Present can go straight back to the first Viewcon.

Source: Internet
Author: User

Latest: I'm not mistaken, I can go straight back to the

such as: A present B then B present C

Now I want to implement the method in C, can go straight back to a, I thought there is a similar method: Self.parentviewcontroller dismiss ...

Who knows just tried not to, later asked the group of brothers said I can be mistaken, only navigationcontroller time can be directly back to Rootviewcontroller, and dismiss can only one layer of the removal

Is there no other way to achieve direct dismiss to a: not also!!!

According to the advice of the brothers in the group:

You just b plus delegate, pop C, c call dismiss, callback notification B also dismiss

Reprinted from: http://blog.csdn.net/kmyhy/article/details/7034202

A view Controller A, pops up a modal View controller b,b and pops up a modal Viewcontroller C?? And so on.

What if you want to go back to the first view controller A, or the M modalview Controller C in front of it, when you're in nth modal view controller?

You must want to dissolve a layer of ground. Yes, I did the same thing at first: dissolve d in C, dissolve C in B, and dissolve B in a. Then you will get an "attempt to dissolve a view Controller that is not currently displayed" error.

Apple's thinking is extraordinary, but you just have to dissolve a modal View controller. That is, at the bottom of the view controller, so that the Modalview controller on top of this layer will be dissolved.

For example: You only use a to dissolve B, then C, D, E, F ... All will be dissolved automatically.

The question is, how do you get a in F? If it is iOS 4, you can use Parentviewcontroller to get the "Parent view Controller" of the current modal viewcontroller and dissolve yourself. If it's iOS 5, you'll have to use Presentingviewcontroller.

In this way, you can keep ParentViewController.parentViewController.parentViewController down.

Code:

if ([Self respondstoselector: @selector (Presentingviewcontroller)]) {    // for IOS 5+   Else  {   // for pre IOS 5}

The problem is, sometimes you're not sure which level of the chain the current modal View controller is. For example, there is a workflow, it has two branches in B, one is A->b->c->d, one is a->b->d, which branch to follow, depending on the user's choice. Regardless of D or F, after processing, return to a to refresh.

When you go back to a in D this place, you can't decide how many parentviewcontroller you want to return a. Because it could be 3 (branch 1), it could be 2 (branch 2). In this case you only have to use the agreement or the Commission. Take a as a delegate, and continue to pass along the workflow, so that regardless of the process of branching 1 or branching 2, D always has a reference to a. When the work of D is completed, call the Protocol method of a implementation directly, and dissolve B in this method of a.

Present can go straight back to the first Viewcon.

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.