iphone - 如何在NavigationController上弹出UIViewController并同时推送UIView

标签 iphone ios uiviewcontroller uinavigationcontroller

我在 UINavigationController 上遇到问题...

我有这个层次结构

UINavigationController
 |- root controller
 |- ViewController A

我在ViewController A中有一个按钮做某事并插入ViewController B ,但我想删除 ViewController A添加ViewController B之前

所以处理后的层次结构是这样的

UINavigationController
 |- root controller
 |- ViewController B

它应该是从 ViewController A 滑动的至 ViewController B ,但如果按返回键,则会返回 root Controller

提前谢谢你。

最佳答案

您应该使用 UINavigationController 的 setViewControllers 方法,并简单地将 root 和 viewController B 添加为数组

//get the existing navigationController view stack
NSMutableArray* newViewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];

//drop the last viewController and replace it with the new one!
ViewControllerB *childController = [[ViewControllerB alloc] initWithNibName:@"ViewControllerB" bundle:nil];
[newViewControllers replaceObjectAtIndex:newViewControllers.count-1 withObject:self];

//set the new view Controllers in the navigationController Stack
[self.navigationController setViewControllers:newViewControllers animated:YES];

关于iphone - 如何在NavigationController上弹出UIViewController并同时推送UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12933007/

相关文章:

iphone - 图层阴影的不透明度

iphone - 如何在iOS中实现剧烈的Shake?

ios - 从后台进入前台时无法显示admob插页式广告

ios - 调用performSegueWithIdentifier后获取重复的UIViewController实例

ios - 覆盖核心数据值

ios - 将一个 NSString 常量分配给另一个

ios - 未知对象类型的zlib解压方法

ios - 如何在 Swift 3.0 中使用 SDWebImage 使用完成 block ?

ios - 当任何其他 UIViewController 被插入堆栈时如何从 UITabBarController 隐藏 TabBar

c# - OpenGL ES 2.0/MonoTouch : Texture is colorized red