简体   繁体   中英

How to push the viewController after the next one connected in the storyboard

What is the strategy & API we can use to push to a viewController after the next one while retaining the view hierarchy?

So for example when the state of the rootViewController is one way i want to show a list of collections. When the state of the rootViewController is another way i want to show the details of one of those collections AND preserve the navigation hierarchy so that we can pop one level back to the collection and pop a second time to the rootViewController.

A possible solution would be to check the state of the rootViewController in the middleVC and have the middleViewController decided whether or not to push the 3rd ViewController. I'm not a fan of that idea because logic that belongs in the rootViewController is now in the middleVC and that seems like breaking encapsulation. Is it?

Thanks for the advice.

As I can suggest you is to push your third view controller as usual, the put you [navigationController viewControllers] in NSArray then insert your second viewController at index 1

So you are at the rootViewController Controller1 index 0

you push your desired viewController Controller3 index 1

then you insert Controller2 at index 1 so your Controller3 become index 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM