简体   繁体   English

将视图从另一个选项卡的模式推送到导航

[英]Push view to navigation from modal of another tab

I'm quite new to iOS programming and I'm trying to do something that I think is simple but I can't find clear explanation. 我是iOS编程的新手,我正在尝试做一些我认为很简单的事情,但是找不到明确的解释。 I'm trying to develop an app with Xcode 6.3 and swift 1.2 我正在尝试使用Xcode 6.3和Swift 1.2开发应用程序

I have this : 我有这个 :

Xcode中的情节提要

So I'm in a tab based application. 因此,我处于基于选项卡的应用程序中。 Each tab view are inside navigation controller. 每个选项卡视图都在导航控制器内部。 D is a modal launch from C . DC的模式发射。 When I click on a button inside D I want to go to B . 当我单击D内的按钮时,我想转到B。 This is fine. 这可以。 But I would like also to display the top navigation bar with a back button pointing to A . 但我也想显示顶部导航栏,并带有指向A的后退按钮。 For now when I tried to use the push segue from D to B , B is shown as modal but not part of the navigation controller. 现在,当我尝试使用从DB的推送功能时, B显示为模态,但不是导航控制器的一部分。

How I have to achieve this easily ? 我要如何轻松实现这一目标? Do I have to recreate all the stack by instantiating each view (A then B) and push everything onto the navigation stack ? 我是否必须通过实例化每个视图(从A到B)来重新创建所有堆栈并将所有内容推送到导航堆栈上?

If you know the code to achieve this in objective-c it's fine for me as well. 如果您知道在Objective-C中实现此目标的代码,对我也很好。

When I click on a button inside D I want to go to B . 当我单击D内的按钮时,我想转到B。 This is fine. 这可以。 But I would like also to display the top navigation bar with a back button pointing to A . 但我也想显示顶部导航栏,并带有指向A的后退按钮。

You can only go back to A , if it is actually on the navigation stack . 如果它实际上在导航堆栈中 ,则只能返回 A。 So, you will have to somehow push it onto the stack before you can achieve your goal. 因此,您必须以某种方式将其推入堆栈,然后才能实现目标。

As a general hint, if you want a view controller to show the navigation bar, you only have to make sure it's embedded into a navigation controller. 作为一般提示,如果希望视图控制器显示导航栏,则只需确保将其嵌入到导航控制器中即可。 When you present a view modally, it will not by default be embedded into a navigation controller. 模态显示视图时,默认情况下不会将其嵌入到导航控制器中。 So, as you said D is shown modally from C , just embed D into another navigation controller and instead of making D the destination for the modal segue, make the navigation controller the destination. 因此,正如您所说的, D是从C模态显示的,只是将D嵌入到另一个导航控制器中,而不是将D用作模态搜索的目的地,而是将导航控制器作为目的地。

Update 更新资料

If you want to show a back button in B that points to A , even though B was shown modally from D , you will have to hack your way around because A is not on the navigation stack. 如果要在B中显示一个指向A的后退按钮, 即使B是从D模态显示的 ,则由于A不在导航堆栈中,您将不得不四处寻找。 So, logically, what you have to do is make sure that A is on the navigation stack just before B . 因此,从逻辑上讲,您要做的是确保A在导航堆栈上紧挨B。 I don't think you can do this simply with segues from IB, but rather use code and instantiate the UINavigationController yourself: 我不认为您可以仅使用IB的segue来做到这一点,而是使用代码并自己实例化UINavigationController

- (void)showBModallyWithBackButtonToA
{
    A *a = [[A alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:a];
    B *b = [[B alloc] init];
    [nav pushViewController:b animated:NO];
    [self presentViewController:nav animated:YES completion:nil];
}

This code has to be executed from D , if I understand your setup correctly. 如果我正确理解了您的设置,则必须从D执行此代码。

Here is the solution from nburk converted in swift with the use of storyboard : 这是nburk通过使用Storyboard快速转换的解决方案:

let a = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("aIdentifier") as! ATableViewController
let nav = UINavigationController(rootViewController: a)
let b = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("bIdentifier") as! BViewController
// b parameters here
// b.parameter1 = variable
nav.pushViewController(b, animated:false)
self.presentViewController(nav, animated:true, completion:nil)

Where aIdentifier and bIdentifier are the identifier you set inside storyboard editor for each view and ATableViewController and BViewController their respective ViewController classes. 其中aIdentifier和bIdentifier是您在故事板编辑器中为每个视图设置的标识符,而ATableViewController和BViewController分别是其各自的ViewController类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Storyboard Segues将视图控制器从模态推送到模态父级使用的导航控制器 - Push view controller from modal into navigation controller used by parent of the modal using Storyboard segues 在 swiftui 中显示导航到另一个视图的模态视图 - Present modal view on navigation to another view in swiftui 从Appdelegate导航到选项卡视图 - Navigation from Appdelegate to tab view 从模式视图中推送视图,然后从popToRootView中推送 - Push view from modal view and then popToRootView SwiftUI 从模态视图使用 NavigationLink 推送视图 - SwiftUI Push View with NavigationLink from modal view 从故事板中的模态视图推送视图控制器 - Push View Controllers from Modal View in Storyboard 无法从AppDelegate推送到View Controller而不会丢失导航栏和标签栏设置iOS - Can't push to View Controller from AppDelegate without losing Navigation Bar and Tab Bar setup iOS 从Modal View Controller推入/弹出到另一个View Controller(包括图片) - Push/pop to another view controller from a Modal View Controller (includes picture) 如何从标签栏视图 controller 转到另一个视图,该视图是导航 controller 的子视图 - How to segue from tab bar view controller to another view which is a child of a navigation controller 如何将视图控制器推送到iOS中标签栏中的导航控制器 - how to push a view controller to a navigation controller in a tab bar in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM