简体   繁体   English

通过代码加载情节提要场景

[英]Loading storyboard scene through code

I'm very new to storyboards and objective-c in general. 一般来说,我对情节提要和Objective-c还是很陌生。 Basically, I have a welcome screen with 4 buttons on it. 基本上,我有一个带有4个按钮的欢迎屏幕。 Each button loads a new scene via the modal way. 每个按钮通过modal方式加载一个新场景。 One of the screens requires an internet connection. 屏幕之一需要互联网连接。 I have already setup the function to check to see if there is internet. 我已经设置了该功能来检查是否有互联网。 If there is no connection, I'd like it to load a separate scene. 如果没有连接,我希望它加载一个单独的场景。 It looks like this ( webView is the name of my UIWebView ): 看起来像这样( webView是我的UIWebView的名称):

-(void)webView:(UIWebView *)myWebView didFailLoadWithError:(NSError *)error {
//code
}

Now, the only issue I'm having is how to load the scene that it should direct to in this function. 现在,我唯一遇到的问题是如何在此函数中加载应定向到的场景。 I have the feeling that I need to start by creating an outlet for this specific scene, but I'm unsure of how to even do that. 我觉得我需要为此特定场景创建一个出口,但是我不确定该怎么做。 I tried searching for a guide on how to do it, but it is all going over my head since I'm so new to programming. 我曾尝试寻找有关如何执行操作的指南,但是由于我对编程还很陌生,所以这一切都困扰我。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

1.) Set your project to use your storyboard inside of the project target's settings 1.)将项目设置为在项目目标的设置内使用情节提要

2.) Inside storyboard, set which scene/class you want to load first by checking off the "Is Initial View Controller" property. 2.)在情节提要板中,通过选中“是初始视图控制器”属性来设置要首先加载的场景/类。

3.) Set up and segue through whatever other scenes/classes you have set up first 3.)设置并选择您首先设置的其他场景/课程

4.) Then when you reach the scene in question, have two different segues set up inside of your storyboard: one for if there's an internet connection and one if there isn't 4.)然后,当您到达有问题的场景时,在情节提要板中设置两种不同的设置:一种用于是否可以连接互联网,另一种可以用于没有互联网连接的情况

5.) Check that condition and call performSegueWithIdentifier: and pass in the identifier that fulfills the internet connection critieria 5.)检查条件并调用performSegueWithIdentifier:并传递满足互联网连接条件的标识符

If you are talking about UIViewController when you are saying scene the there is a rely easy way to do it, just call the following in your desired method (off course with the required name changes) 如果您在说scene时谈论的是UIViewController ,那么有一种简便的方法可以执行此操作,只需在所需方法中调用以下内容即可(当然,需要更改名称)

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryboardName" bundle:nil];
YourViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIdentifier"];

Now make sure that your storyboard has a UIViewController of type YourViewController and that UIViewController has YourViewControllerIdentifier as identifier set in the storyboard. 现在,确保情节提要具有类型为YourViewController的UIViewController,并且确保UIViewController的情节YourViewControllerIdentifier中将YourViewControllerIdentifier作为标识符设置。

Now if you are talking about a custom UIView when you are saying scene then you can't do that, you can't load a custom UIView from a sotryboard without loading the proper view controller. 现在,如果您在说scene时谈论的是自定义UIView ,那么您将无法做到这一点,因此,如果不加载适当的视图控制器,就无法从sotryboard加载自定义UIView。 But you can create a custom UIView with a .xib file and load it on your desired methods. 但是,您可以使用.xib文件创建自定义UIView并将其加载到所需的方法上。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM