如何从 iOS 游乐场中的文件实例化 Storyboard? [英] How do you instantiate a Storyboard from a file within an iOS playground?

查看:32
本文介绍了如何从 iOS 游乐场中的文件实例化 Storyboard?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您已将 Main.storyboard 从 Xcode 6 项目复制到独立 Playground 的 Resources 目录中.如何使用 Main.storyboard 文件实例化 UIStoryboard?尝试通过 nil 使用默认值不起作用:

Let's assume you've copied a Main.storyboard from an Xcode 6 project into a standalone playground's Resources directory. How can you instantiate a UIStoryboard using the Main.storyboard file? Trying to use the default via nil doesn't work:

let storyboard = UIStoryboard(name: "Main", bundle: nil)

也没有明确使用主包:

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

即使 Playground 是情节提要的 Xcode 项目的一部分,我也会收到同样的错误:在捆绑 NSBundle 中找不到名为‘main’的情节提要..."

Even if the playground is part of the storyboard's Xcode project, I receive the same error: "Could not find a storyboard named 'main' in bundle NSBundle..."

似乎捆绑路径是正确的,应该能够反序列化故事板文件.

Seems that the bundle path is correct and should be able to deserialize the storyboard file.

推荐答案

我发现了这个:

你可以将一个xib文件扔到你的资源中,但是playground无法读取或运行它,因为它不是编译形式.今天,我(终于!)想到使用ibtool来预编译我的MainMenu.xib文件进入 nib 然后加载它.当你安装 Xcode 的命令行工具时,ibtool 被添加到/usr/bin.所以你需要做的就是编译你的 nib 是发出以下命令:

"You can throw a xib file into your Resources, but the playground cannot read it or run it because it’s not in compiled form. Today, I (finallly!) thought of using ibtool to pre-compile my MainMenu.xib file into nib and then load that. When you install Xcode’s command line tools, ibtool gets added to /usr/bin. So all you need to do to compile your nib is issue the following command:

ibtool --compile MainMenu.nib MainMenu.xib`

将生成的笔尖放入您的 Playground 的资源文件夹中,您就可以加载它了."

Throw that resulting nib into your playground’s resources folder and you’re ready to load it up."

http://ericasadun.com/2015/03/25/swift-todays-wow-moment-adding-menus-to-playgrounds/

您的故事板将被编译成多个笔尖(每个场景一个)

Your storyboard will be compiled into multiple nibs (one per scene)

希望能帮到你

这篇关于如何从 iOS 游乐场中的文件实例化 Storyboard?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆