![](/img/trans.png)
[英]How to present a view controller that is in the “main” storyboard from a view controller that isn't in the storyboard but is created programmatically?
[英]Present View From Storyboard Programmatically
我对使用情节提要非常陌生,并且正在尝试学习。 在我的应用程序中,我想以模态方式从一个视图更改为另一个视图,而无需按任何按钮,即计时器运行完毕然后执行操作。 我在主视图中添加了一个通知观察器,在情节URLWebViewController
,添加了一个新的视图控制器,并将Custom Class与其关联起来,称为URLWebViewController
。 在代码中,我写道:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
URLWebViewController *myVC = (URLWebViewController *)[storyboard instantiateViewControllerWithIdentifier:@"URLWeb"];
[self presentViewController:myVC animated:YES completion:nil];
但是我收到警告消息
Incompatible pointer types sending 'URLWebViewController' to parameter of type 'UIViewController'
就像我说的那样,我对Storyboards非常陌生,这是当前的样子:
屏幕快照表明您尚未在两个视图控制器之间创建序列。 通过从一个视图控制器单击并拖动到另一个视图控制器来执行此操作。 在属性检查器中,为您新创建的segue提供一个标识符,即,一个为其命名的字符串。
要以编程方式触发此segue,请在您的源视图控制器(您从中进行segue的控制器)中调用performSegueWithIdentifier
并传入您选择的标识符。
真的很简单! 我不了解顺序,但假设您要从ViewController
传递到WebViewController
(故事板中的名称)。只需从ViewController
到WebViewController
ctrl拖动即可创建序列并选择modal
作为类型。
现在,单击连接视图控制器的行,并在右侧面板中为其指定一个标识符。 现在,在您的代码中,只需使用您编写的标识符使用performSegueWithIdentifier
方法即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.