How iOS randomly jumps, push to pop

Source: Internet
Author: User

How can iOS casually jump, push to pop?

Theme ideas: such as a, B, C, D four view controller.

After a push B is wanted, B is on push to D, then from D Pop to C, in a from C pop

Here's how to fix it:

1. If at this time under a controller, want to push to B, you can write

[Self.navigationcontroller pushviewcontroller:b: YES]; At this time self.navigationController.viewControllers in order contains [a, b]

2. At this point to the B controller, the next is push to D, you can write

[Self.navigationcontroller pushviewcontroller:d: YES];

At this time self.navigationController.viewControllers in order to contain [a,b,d], next very important, how to think from D Pop to C, see array [a,b,d] There is no c how to pop to C?

You will need to modify this array to add C.

So you will write as follows:

[Self.navigationController.viewControllers ADDOBJECT:C];

Found an error, this is because Self.navigationController.viewControllers is an immutable group, there is no way, we had to change it:

Nsmutablearray*tempmarr =[nsmutablearrayarraywitharray:self.navigationcontroller.viewcontrollers];

At this time to add C is much easier, gee, smart you will find from D pop C can not directly addobject C directly;

Of course, I would do this:

2];

This time Tempmarr is like this [a,b,c,d], but in order to from C Pop to A, the array can not have B

You need to turn Tempmarr into [a,c,d], and as for how to change, you know more than I do,

Students who know how to think will find that the self.navigationController.viewControllers is still [a,b,d], do not worry, do not fear navigationcontroller have such a method, can be done, as follows:

[Self.navigationcontroller Setviewcontrollers:tempmarr Animated:yes];

Some students will say, this is not directly to replace B to C?

It looks like this, but jump timing, timing, timing important things to say three times, there are views of the switch, toggle, toggle ...

At this point in the B controller, these processes are processed in B, and must be B after the push to the D method, which means

[Self.navigationcontroller pushviewcontroller:d Animated:yes];

After the array processing;

Additional code:

Processing in the B controller:

-(void) pushtest {    [Self.navigationcontroller pushviewcontroller:d animated:yes];       Nsmutablearray*tempmarr = [NSMutableArrayarrayWithArray:self.navigationController.viewControllers];    [Tempmarr insertobject:c AtIndex:tempMarr.count 2 ];     // now self means b, because in B     [Self.navigationcontroller Setviewcontrollers:tempmarr animated:yes];}

How iOS randomly jumps, push to pop

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.