在同一操作中弹出和推送视图控制器
是否可以从导航堆栈中弹出一个视图,然后将另一个视图直接推入其中?
我正在尝试为此部分实现一个平面层次结构,并且希望有一个分段控制器,但我无法使分段控制器看起来像我想要的那样,因此我尝试使用导航控制器。
单击按钮时,我执行了以下代码:
[[self navigationController] popViewControllerAnimated:YES];
MapsViewController *aViewController = [[MapsViewController alloc]
initWithNibName:@"MapsViewController" bundle:nil];
[self.navigationController pushViewController:aViewController animated:NO];
[aViewController release];
它弹出正常,但没有任何推动的迹象!任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
或者
Or
在 Swift 中:
如果 Storyboard 中存在 newVc:
In Swift:
In case newVc exists in a Storyboard:
取自 https://stackoverflow.com/users/1619554/tomer-peled 的解决方案,以便其他人可以更容易找到它。
这似乎是 iOS8 的最佳方法:
Taken from https://stackoverflow.com/users/1619554/tomer-peled 's solution, so others can find it more easily.
This appears to be the best way to do it for iOS8:
Swift 4 :
self.navigationController.setViewControllers[]..
不适合我。但我可以通过将导航控制器保存在实例变量中并执行推送/弹出操作来解决问题。因此,能够默默地更换控制器而不会出现故障。Swift 4 :
self.navigationController.setViewControllers[]..
doesn't worked out for me. But I am able to solve the issue by holding a navigation controller in an instance variable and do push/pop operation. Thus, silently able to change controller without glitch.您可以使用此代码来弹出或推送控制器。
对于目标 c
对于 Swift
You can use this code to pop or push your controller.
For objective c
For Swift
Swift 3.0
如果有人想深入了解视图层次结构:
Swift 3.0
In case someone wants to go deep into the view hierarchy:
这可以通过在
UINavigationController
上添加扩展来实现,如下所示:并使用
popAndPushViewController
代替navigationController
的pushViewController
方法> UIViewController 上的实例。举个例子:
This can be achieved by adding an extension on
UINavigationController
as follows:And use
popAndPushViewController
in place ofpushViewController
method ofnavigationController
instance onUIViewController
.As an example: