【问题标题】:Is it possible to load a storyboard in an iOS Playground?是否可以在 iOS Playground 中加载故事板?
【发布时间】:2018-04-01 17:03:14
【问题描述】:

是否可以在 iOS Playground 中加载故事板? 请按照此问题中的步骤操作:

How do you instantiate a Storyboard from a file within an iOS playground?

使用

编译 Main.storyboard
ibtool --compile MainMenu.nib MainMenu.storyboard

将其添加到 Playground 的 Resources 文件夹中。然后尝试加载它:

let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())

这会导致错误:

Playground execution aborted: Execution was interrupted, reason: signal SIGABRT.

XCode 7.3.1 甚至 XCode 8 是否支持此功能?

【问题讨论】:

  • 不是整个故事板文件,但您可以插入您想要的设计。因为 StoryBoard 本身就是一个文件。
  • @Jack 不太明白。你能改写吗,拜托。你的意思是我可以添加一个 xib 吗?

标签: ios swift swift-playground


【解决方案1】:

如果我将 Playground 的资源部分设置为与应用程序相同的结构,则您的故事板初始化代码对我有用。

Resources->Base.lproj->Main.storyboardc

【讨论】:

  • 你能分享你的项目吗?我无法重现。你也编译了 .storyboard 吗?
  • 我从已编译的示例应用程序中复制了一个 Base.lproj 文件夹并将其添加到资源中,所以,是的,它是一个已编译的故事板。
  • 我以为“storyboardc”只是拼错了
【解决方案2】:

经过多次尝试,我终于得到了这个工作。一些警告:

1.. 使用

编译情节提要
ibtool --compile MainMenu.storyboardc MainMenu.storyboard

不使用

ibtool --compile MainMenu.nib MainMenu.storyboard

2..将编译好的storyboardc文件放在playground的Resources文件夹中,而不是Sources文件夹中

3.. 编译时使用 --module 标志指定模块名称。否则,您的网点可能会导致运行时错误。对于 Playground 书籍,模块名称为 Book_Sources。对于您自己的游乐场,模块名称为 [Playground name]_Sources。请注意,我在 Apple 的文档中没有找到任何这些内容,因此它可能会发生变化。 最终命令如下所示:

ibtool --compile MainMenu.storyboardc MainMenu.storyboard --module Book_Sources

【讨论】:

  • @HaoDong 我添加了一些关于我刚刚发现的模块的信息。看看这次是否有效。
猜你喜欢
  • 1970-01-01
  • 2012-01-30
  • 1970-01-01
  • 2011-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
  • 1970-01-01
相关资源
最近更新 更多