简体   繁体   中英

Push view controller is not pushing on ios 7

I have 3 VC(view controller) (VC1, VC2, VC3).

At VC1, I used the code:

self.navViewController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.navViewController.view.frame = CGRectMake(self.view.frame.size.width - viewController.view.frame.size.width, 
                                               viewController.view.frame.origin.y, 
                                               viewController.view.frame.size.width, 
                                               viewController.view.frame.size.height);
[self.navigationController addChildViewController:self.navViewController];
[self.navigationController.view addSubview:self.navViewController.view];
[self.navViewController didMoveToParentViewController:self.navigationController];

The VC2 is showing, and then at VC2 I used the code to push navigation controller to VC3

VC3 *vc3 = [[VC3 alloc] initWithNibName:@"VC3" bundle:nil];
[vc3.view updateConstraintsIfNeeded];
[self.navigationController pushViewController:vc3 animated:YES];

Currently, when I'm adding snippet code [vc3.view updateConstraintsIfNeeded]; . I saw navigation of changed and content view does not change and show. It just shows a content view of VC2.

In my project, I'm using auto layout. I tried remove auto layout on my project it works well. When I added auto layout it works wrong.

It just occurs on iOS 7, iOS 8 work well.

Please, help me to resolve the bug. Many thanks!

The problem is you are displaying your VC2 on top of the pushed view controller. What is the reason to have one view controller as a child of a navigation controller? Instead, have a common ancestor of both VC2 and the navigation controller, or put your VC2 somewhere else in the view hierarchy, not on top of of the navigation controller's view , which holds the entire navigation controller (including contained controllers in the push stack) view hierarchy.

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