有可能在故事板中引用其他故事板吗?

时间:2022-12-06 10:35:55

I am working on an iOS app and I want to split it into a couple of Storyboards, the problem is that I can't seem to figure out a way to setup references between Storyboards as an entry point.

我正在开发一个iOS应用程序,我想把它分成两个故事板,问题是我似乎无法找到一种方法来在故事板之间设置引用作为切入点。

For example I want my Main.storyboard to look something like this:

例如,我想要我的主服务器。故事板看起来像这样:

--> Authentication Storyboard --> Tabbed Storyboard --> ...

——>认证故事板——> Tabbed故事板——>…

I am new to iOS development and I would expect this to be simple, but can't seem to find a way to do it.

我是iOS开发的新手,我认为这很简单,但似乎找不到一种方法。

3 个解决方案

#1


2  

Yes you can use multiple Storyboards in a project BUT No, you cant reference them directly from inside another storyboard.

是的,你可以在一个项目中使用多个故事板,但是不行,你不能直接从另一个故事板中引用它们。

Referencing a Storyboard to use on launch

在启动时引用故事板

Your project target can use any of the storyboards contained within it. The reference for the storyboard entry point can be found in the target settings.

您的项目目标可以使用其中包含的任何故事板。故事板入口点的引用可以在目标设置中找到。

有可能在故事板中引用其他故事板吗?

  1. Select the target
  2. 选择目标
  3. Select the General Tab
  4. 选择“常规”选项卡上
  5. In the dropdown for main interface select which storyboard to use initially.
  6. 在主界面的下拉菜单中选择最初要使用的故事板。

Referencing a Storyboard in code

在代码中引用故事板

So in this example I wish to push a viewcontroller onto a navigation Controller. The viewcontroller I want to reference may be in a different storyboard or the current one I'm using. The code doesn't care...

在这个例子中,我想把一个viewcontroller推到导航控制器上。我要引用的viewcontroller可能在不同的故事板中或者我正在使用的当前故事板中。代码不关心…

    if let storyboard = UIStoryboard(name: "A2ndStoryboard", bundle: nil) {
      if let vc = storyboard.instantiateViewControllerWithIdentifier("SomeViewController" as String) {

        navigationController?.pushViewController(vc, animated: true)
      }
    }

When you want to reference ViewControllers like this you need to ensure that they are identified in the Storyboard correctly:

当你想引用视图控制器时,你需要确保它们在故事板中被正确识别:

有可能在故事板中引用其他故事板吗?

#2


1  

Dont use multiple storyboards. use one storyboard with multiple viewcontrollers with segue between them and embed navigationcontroller. for exa, use one viewcontroller for Authentication like wise another viewcontroller for tabs (tabbarviewcontroller). give segue from authenticationVC to tabbarVC. hope this will help. :)

不要使用多个故事板。使用带有多个视图控制器的故事板,在它们之间使用segue并嵌入navigationcontroller。对于exa,使用一个viewcontroller进行身份验证,就像wise另一个viewcontroller用于制表符(tabbarviewcontroller)。给segue从authenticationVC到tabbarVC。希望这将帮助。:)

#3


0  

As you say you're new to iOS development let me try to recap this for you:

正如你所说,你是iOS开发的新手让我试着为你总结一下:

Interface Builder (IB) is a tool built in to Xcode that helps you design your user interface without any code. Everything IB can do can also be done programmatically. IB supports two different types of files: XIB files and Storyboards.

接口构建器(IB)是一个内置到Xcode中的工具,它可以帮助您在不使用任何代码的情况下设计用户界面。IB所能做的一切也可以通过编程来完成。IB支持两种不同类型的文件:XIB文件和故事板。

XIB files (extension .xib) are collections of UIView objects that you can design using IB.

XIB文件(扩展名. XIB)是您可以使用IB设计的UIView对象的集合。

Storyboards (extension .storyboard) are collections of UIViewController objects which all have a view property that you can design using IB.

故事板(扩展。storyboard)是UIViewController对象的集合,它们都有一个视图属性,可以使用IB进行设计。

Conlusion: There (currently) is no such thing as an Interface Builder file type which represents a collection of XIBs or Storyboards. Therefore you can't reference a Storyboard within a Storyboard as of now. Instead you can still split your view controllers up into different Storyboards and transition between them programmatically.

Conlusion:目前还没有接口构建器文件类型,它表示xib或故事板的集合。因此你现在不能在故事板中引用故事板。相反,您仍然可以将视图控制器拆分为不同的故事板,并以编程方式在它们之间进行转换。

Here's another thread on SO to help you get started with the programmatic transitions:

下面是另一个线程,帮助您开始编程转换:

How can I load storyboard programmatically from class?

如何从类中以编程方式加载故事板?

I hope this helps.

我希望这可以帮助。

#1


2  

Yes you can use multiple Storyboards in a project BUT No, you cant reference them directly from inside another storyboard.

是的,你可以在一个项目中使用多个故事板,但是不行,你不能直接从另一个故事板中引用它们。

Referencing a Storyboard to use on launch

在启动时引用故事板

Your project target can use any of the storyboards contained within it. The reference for the storyboard entry point can be found in the target settings.

您的项目目标可以使用其中包含的任何故事板。故事板入口点的引用可以在目标设置中找到。

有可能在故事板中引用其他故事板吗?

  1. Select the target
  2. 选择目标
  3. Select the General Tab
  4. 选择“常规”选项卡上
  5. In the dropdown for main interface select which storyboard to use initially.
  6. 在主界面的下拉菜单中选择最初要使用的故事板。

Referencing a Storyboard in code

在代码中引用故事板

So in this example I wish to push a viewcontroller onto a navigation Controller. The viewcontroller I want to reference may be in a different storyboard or the current one I'm using. The code doesn't care...

在这个例子中,我想把一个viewcontroller推到导航控制器上。我要引用的viewcontroller可能在不同的故事板中或者我正在使用的当前故事板中。代码不关心…

    if let storyboard = UIStoryboard(name: "A2ndStoryboard", bundle: nil) {
      if let vc = storyboard.instantiateViewControllerWithIdentifier("SomeViewController" as String) {

        navigationController?.pushViewController(vc, animated: true)
      }
    }

When you want to reference ViewControllers like this you need to ensure that they are identified in the Storyboard correctly:

当你想引用视图控制器时,你需要确保它们在故事板中被正确识别:

有可能在故事板中引用其他故事板吗?

#2


1  

Dont use multiple storyboards. use one storyboard with multiple viewcontrollers with segue between them and embed navigationcontroller. for exa, use one viewcontroller for Authentication like wise another viewcontroller for tabs (tabbarviewcontroller). give segue from authenticationVC to tabbarVC. hope this will help. :)

不要使用多个故事板。使用带有多个视图控制器的故事板,在它们之间使用segue并嵌入navigationcontroller。对于exa,使用一个viewcontroller进行身份验证,就像wise另一个viewcontroller用于制表符(tabbarviewcontroller)。给segue从authenticationVC到tabbarVC。希望这将帮助。:)

#3


0  

As you say you're new to iOS development let me try to recap this for you:

正如你所说,你是iOS开发的新手让我试着为你总结一下:

Interface Builder (IB) is a tool built in to Xcode that helps you design your user interface without any code. Everything IB can do can also be done programmatically. IB supports two different types of files: XIB files and Storyboards.

接口构建器(IB)是一个内置到Xcode中的工具,它可以帮助您在不使用任何代码的情况下设计用户界面。IB所能做的一切也可以通过编程来完成。IB支持两种不同类型的文件:XIB文件和故事板。

XIB files (extension .xib) are collections of UIView objects that you can design using IB.

XIB文件(扩展名. XIB)是您可以使用IB设计的UIView对象的集合。

Storyboards (extension .storyboard) are collections of UIViewController objects which all have a view property that you can design using IB.

故事板(扩展。storyboard)是UIViewController对象的集合,它们都有一个视图属性,可以使用IB进行设计。

Conlusion: There (currently) is no such thing as an Interface Builder file type which represents a collection of XIBs or Storyboards. Therefore you can't reference a Storyboard within a Storyboard as of now. Instead you can still split your view controllers up into different Storyboards and transition between them programmatically.

Conlusion:目前还没有接口构建器文件类型,它表示xib或故事板的集合。因此你现在不能在故事板中引用故事板。相反,您仍然可以将视图控制器拆分为不同的故事板,并以编程方式在它们之间进行转换。

Here's another thread on SO to help you get started with the programmatic transitions:

下面是另一个线程,帮助您开始编程转换:

How can I load storyboard programmatically from class?

如何从类中以编程方式加载故事板?

I hope this helps.

我希望这可以帮助。