缺少使用导航控制器从第一视图控制器到第二视图控制器的过渡
我想创建一个导航层次结构,我想在其中使用NavigationController从FirstViewController转到SecondViewController。 FirstViewController包含一个我打算使用的按钮B。我正在使用导航控制器概念,因为我想稍后返回第一视图controller。我已经完成了以下步骤来实现它:
- 我将导航式controller嵌入了一个故事板X中,其中conteber controller和secondViewController既有。
- 我已经从第一视图中的按钮B创建了一个segue(已与之关联的FirstViewController)到第二视图(具有SecondViewController)。
- 我将NavigationViewController NVC设置为以下内容,如我提出了FirstViewController:
nvc = UINavigationController.init(rootViewController: firstViewController)
- 稍后,当按钮B被按下时,我执行以下代码将SecondViewController推到导航层次结构:
self.nvc?.pushViewController(secondViewController, animated: true)
但是,即使在按下秒数也不显示自身,即使在按住后, 。
- 我将按钮B和SecondViewController之间的SEGUE命名为Ksegue,因此我试图执行SEGUE作为补充,以查看SecondViewController是否表现出来:
self.performSegue(withIdentifier: "kSegue", sender: self)
当第4和第5个步骤一起执行时,就会出现例外。例外指出,我正在推动已经存在于导航层次结构上的ViewController,但是即使我对Performsegue代码进行了评论,第二视图仍然没有打开。
我可以问我在这里犯的错误吗?
I want to create a navigation hierarchy where I want to go to a SecondViewController from FirstViewController using a NavigationController. The FirstViewController contains a button B that I intend to use to go to a SecondViewController. I am employing the navigation controller concept since I want to return to the FirstViewController later. I have done the following steps to achieve it:
- I have embedded a NavigationController into a storyboard X containing both the FirstViewController and SecondViewController.
- I have created a segue from the button B present in the FirstView (has FirstViewController associated with it) to the SecondView (has SecondViewController).
- I set the navigationViewController nvc as following after I have presented the firstViewController:
nvc = UINavigationController.init(rootViewController: firstViewController)
- Later on, when the button B gets pressed, I execute the following code to push the secondViewController onto the navigation hierarchy:
self.nvc?.pushViewController(secondViewController, animated: true)
However, the secondView doesn't present itself even after pushing.
- I have named the segue between the button B and secondViewController as kSegue, so I tried to perform the segue as an addition to see if the secondViewController presents itself or not:
self.performSegue(withIdentifier: "kSegue", sender: self)
An exception occurs when both the 4th and 5th steps are performed together. The exception states that I'm pushing a viewController that already exists on the navigation hierarchy, but the second view still doesn't open even if I comment the performSegue code.
May I ask what mistake I am making here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在故事板中,请确保从导航控制器到第一个视图控制器有一个rootviewController segue。另外,请确保将导航控制器标记为初始视图控制器。
在代码中,更改
为
In the storyboard, make sure there is a rootViewController segue from the navigation controller to the first view controller. Also, make sure the navigation controller is marked as the initial view controller.
In the code, change
To