iOS navigation bar returns to the specified page

Source: Internet
Author: User

There is such a requirement in the implementation of your project. In general, our navigation bar Back button, is the last page to jump over, click the Back button to return to the interface. But some of the actual needs are not so simple. Some interface returns are only determined by the interface. So when I was in the implementation of the time because of the lack of understanding of the mechanism of the jump, resulting in impossible. Later, in the Boss, Lugo (Daniel) understand. First, we need to know that the navigation bar jumps through the form of a stack. So each time we jump, we will have an extra interface object in the stack. The number in the stack increases, and when we need to go back to one of the previous interfaces, we need to look for this interface in the stack. We need an array to hold the information, and when we find the interface, we can jump through the navigation. The following is the implementation of the Code, in fact, very simple. (Our return button needs to be redefined, this is the click Method after the definition)

-(void) backaction{

Uinavigationcontroller *NAVVC = Self.navigationcontroller;

Nsmutablearray *viewcontrollers = [[Nsmutablearray alloc] init];

For (Uiviewcontroller *VC in [NAVVC Viewcontrollers]) {

[Viewcontrollers ADDOBJECT:VC];

if ([VC ISKINDOFCLASS:[MYNEEDJUMPVC Class]]) {

Break

}

}

[NAVVC setviewcontrollers:viewcontrollers Animated:yes];

}?

? Self.navigationcontroller is the current page;

MYNEEDJUMPVC is the page we need to jump to;

It's that simple. Of course, you can also use the number of navigation bar stack to jump, but you need to know the destination page in the number of stacks is a few, this implementation is a bit complex, but also I started the method, and then use the above method to achieve minutes to get it done! Ha ha! What do not understand can give me a message.

iOS navigation bar returns to the specified page

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.