本文介绍了以相同的动作弹出和推送视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从导航堆栈中弹出一个视图,然后将另一个视图直接推送到它上面?
is is possible to pop a view off the navigation stack and then push another straight onto it?
我正在尝试为此部分实现平面层次结构,并希望有一个分段控制器,但我无法使分段控制器看起来像我想要的任何东西,因此我尝试使用导航控制器.
I'm trying to implement a flat hierarchy for this section and would like to have a segmented controller but I can't make the segmented controller look anything liked I want, hence why I'm trying to use the navigation controller.
当一个按钮被点击时,我执行了这段代码:
When a button is clicked I executed this code:
[[self navigationController] popViewControllerAnimated:YES];
MapsViewController *aViewController = [[MapsViewController alloc]
initWithNibName:@"MapsViewController" bundle:nil];
[self.navigationController pushViewController:aViewController animated:NO];
[aViewController release];
它弹出正常,但没有任何推动的迹象!任何帮助将不胜感激.
It's popping off ok but theres no sign of any pushing! Any help would be appreciated.
推荐答案
MapsViewController *aViewController = [[MapsViewController alloc]
initWithNibName:@"MapsViewController" bundle:nil];
// locally store the navigation controller since
// self.navigationController will be nil once we are popped
UINavigationController *navController = self.navigationController;
// retain ourselves so that the controller will still exist once it's popped off
[[self retain] autorelease];
// Pop this controller and replace with another
[navController popViewControllerAnimated:NO];//not to see pop
[navController pushViewController:aViewController animated:YES];//to see push or u can change it to not to see.
或者
MapsViewController *aViewController = [[MapsViewController alloc]
initWithNibName:@"MapsViewController" bundle:nil];
UINavigationController *navController = self.navigationController;
//Get all view controllers in navigation controller currently
NSMutableArray *controllers=[[NSMutableArray alloc] initWithArray:navController.viewControllers] ;
//Remove the last view controller
[controllers removeLastObject];
//set the new set of view controllers
[navController setViewControllers:controllers];
//Push a new view controller
[navController pushViewController:aViewController animated:YES];
这篇关于以相同的动作弹出和推送视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!