如何在执行popToRootViewController后将视图控制器推送到导航堆栈

时间:2011-10-03 05:23:42

标签: objective-c ios pushviewcontroller poptoviewcontroller

我只是在将堆栈弹出到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];

推送不起作用,即没有显示新页面。似乎popToRootViewController导致这种情况发生(确切地说不确定)。关于如何弹出然后推新页面的任何建议?

1 个答案:

答案 0 :(得分:2)

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];