简体   繁体   中英

How to navigate a child view controller from other child view controller in objective c

I want to navigate to a view controller from another controller. Both view controllers are child of root view controller of navigation view controller. Now I want to navigate to a second view controller from the first view controller and same as first view controller from second view controller using navigation view controller. How to do that?

The Storyboard image is as follows :

在此处输入图片说明

You can setup NavigationController with rootViewController is Controller1

when navigation to Controller2 (from Viewcontroller1) just push viewController2 to navigation controller.

when navigation to Controller1 (from Viewcontroller2) just pop viewController2 from navigation controller (or pop to viewController1).

Make another segue from first View Controller to Second View Controller & give it Push navigation.Also give identifier to segue like 'ABCSegue'. Then On the action of Button write

[self performSegueWithIdentifier:@"ABCSegue" sender:nil];

Do same for navigate from second view controller to first view controller. Hope this will help you.

you can just drag a segue from child1's button to child2, and child2's button to child1, though the storyboard will look ugly, but it works. or you can just use

[self.navigationController pushViewController:child2 animated:YES];

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