简体   繁体   English

从当前的视图控制器中打开一个新的ViewController

[英]Open a new ViewController from a current view controller

I know there are a few other question out there like this, however I'm not able to get any of them to work. 我知道这里还有其他一些问题,但是我无法让其中任何一个工作。 I think I need a little more clarification that I'm attacking this correctly. 我想我需要进一步澄清一下我正在正确地进行攻击。

I have a story board that I have a NavigationController on with a segue to a ViewController that contains a webview. 我有一个故事板,上面有一个NavigationController,并带有一个包含Webview的ViewController。 I have successfully captured the the click on my webview and I would like it to open in a new ViewController that also contains a webview. 我已经成功捕获了Webview上的点击,我希望它在一个也包含Webview的新ViewController中打开。 I have added a second ViewController with a webview on to my storyboard, but can't figure out how to add a segue to it. 我在情节提要中添加了第二个具有Webview的ViewController,但无法弄清楚如何为其添加序列。 I also tried making the connection in the code by adding the following to my shouldStartLoadWithRequest method of my first ViewController: 我还尝试通过将以下内容添加到我的第一个ViewController的shouldStartLoadWithRequest方法中来建立代码连接:

    SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self presentViewController:secondViewController animated:YES completion:nil];

However it never opens my second ViewController, it just stays in the first ViewController. 但是,它永远不会打开我的第二个ViewController,而是停留在第一个ViewController中。 I'm a noob and I'm sure I'm missing something somewhere? 我是菜鸟,可以确定我在某处缺少什么吗?

Just add the segue from one view controller to the other (not connected to any specific button), and then give the segue an identifier. 只需将一个视图控制器中的序列添加到另一个视图控制器(未连接到任何特定按钮),然后为该序列提供一个标识符。

Then, in your code, remove the initWithNibName , because you don't have a NIB. 然后,在您的代码中,删除initWithNibName ,因为您没有NIB。 Instead, use performSegueWithIdentifier:sender: . 而是使用performSegueWithIdentifier:sender: You will also likely want to use prepareForSegue:sender: in order to pass the appropriate URL / HTML information that should be loaded into the second web view. 您可能还需要使用prepareForSegue:sender:以传递应加载到第二个Web视图中的适当的URL / HTML信息。

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

相关问题 Swift 3 - 关闭当前的 ViewController 并打开新的 ViewController - Swift 3 - Close current ViewController and Open new ViewController 关闭当前视图控制器并打开新的视图控制器-iOS Swift - Dismiss Current View controller and open new view controller - ios Swift 展开到不在当前导航视图控制器链中的viewController - Unwind to a viewController that is not in the current navigation view controller chain 从具有滚动视图的视图中打开新的视图控制器 - open new view controller from view with scroll view iOS中弹出窗口的同一视图控制器中的新视图控制器或新视图 - New viewcontroller or new view in the same view controller for pop ups in iOS 从子级Viewcontroller(Tab)传递到视图控制器 - Pass from a child Viewcontroller (Tab) to a view controller 如何从集合视图中打开视图控制器? - how open viewcontroller from collection view? 从滚动视图打开图像到新的视图控制器 - open an image from a scrollview into a new viewcontroller Swift 4-如何从当前视图控制器设置和显示新的根视图控制器 - Swift 4 - How to set and show a new root view controller from current view controller 当用户点击推送通知时,关闭当前ViewController并打开新ViewController的最佳方法是什么 - When user tap push notification, what is the best way to close current viewcontroller and open new viewcontroller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM