简体   繁体   中英

Control segue destination Back button Navigation bar

I have 4 views embedded in a Navigation Bar:

VC1 -> VC2 -> VC3 -> VC4

I need Back button from VC3 to be segued to VC1 instead of VC2. I have searched to implement this option but I wasn't successful. Is it possible?

Many thanks

You can't change the behavior of the back button if you want it to keep it's normal appearance, but you could resort to a dirty fix (I'm not familiar with a better way of doing this) if you can't organize your application better. It involves editing the navigation stack directly and removing the view controller you don't need from it.

It's not a recommended way of handling this, but it gets the things done:

NSMutableArray *myNavigationStack = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[myNAvigationStack removeObjectAtIndex:<yourViewControllerExtraIndex>];
self.navigationController.viewControllers = navigationStack;

Make sure you get the right index (0 being your rootViewController), and to handle your memory properly.

Probably the best way of going around this is to design the architecture of your application to avoid this kind of behavior completely.

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