简体   繁体   中英

How to push a view controller onto navigation stack AFTER executing popToRootViewController

I am trying to push a new view controller onto a navigation stack only after I pop the stack to rootviewcontroller

//Select the tab I want to go to
self.tabBarController.selectedIndex = FEEDPAGE_INDEX;

//Retrieve the navcon in the feed page
UINavigationController *navcon = (UINavigationController*)[self.tabBarController.viewControllers objectAtIndex:FEEDTAB_INDEX];

//Pop to root view controller here
[navcon popToRootViewControllerAnimated:YES];

//Push a new root view controller onto stack
QuestionAnswerViewController *x = [[QuestionAnswerViewController alloc]init];
[navcon pushViewController:x animated:YES];

The push didn't work ie no new page was displayed. It seemed that the popToRootViewController causes this to happen (not sure exactly). Any advise on how I can pop and then push a new page?

QuestionAnswerViewController *x = [[QuestionAnswerViewController alloc]init];
UINavigationController *navcon = (UINavigationController*)[self.tabBarController.viewControllers objectAtIndex:FEEDTAB_INDEX];
NSArray *arr = [navcon viewControllers];
NSArray *newStack = [NSArray arrayWithObjects:[arr objectAtIndex:0], x, nil];
[navcon setViewControllers:newStack];

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