xcode 如何将基于 NIB 的项目转换为基于 Storyboard 的项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8208499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert a NIB-based project to a Storyboard-based?
提问by Xander
I'm using storyboard (this is completely new!).
我正在使用故事板(这是全新的!)。
How do I import my existing xib files and integrate them onto a single file, using the storyboard option?
如何使用情节提要选项导入现有的 xib 文件并将它们集成到单个文件中?
回答by T.J.
There is not a 1-click way to do this. According to "Sams Teach Yourself Core Data for Mac and iOS in 24 Hours" by Jesse Feiler, storyboards are different enough in their developer interfaces that it makes sense not to convert existing nib but to use them for new projects. One of the larger differences the way view transitions are handled. However, I did take the plunge and feel it was worth it because I was still near the beginning of a larger project. Doing so will entail a manual process. Apple Converting to Storyboards Release Notesaddresses how to add storyboard to the project. This will get you a storyboard but your existing xibs will not be imported into the storyboard. I didn't do this. I started with a fresh project and copied over the custom view controller classes I wanted to re-use (.h and .m). Then I proceeded to build my storyboard and cut and pasted from the old projects xib files using interface builder when it made sense. It really doesn't take that long. After you assign your custom view controllers to the control your views in storyboard you will want to take out the IBActions out of your code that select view transitions and replace them with storyboard segues. The segues are added in storyboard and you have the option of adding a prepareForSegue method in your view controller. The optional prepareForSegue method is used finishing up anything in the source view controller and setting up the destination view controller before the transition.
没有一键式的方式来做到这一点。根据 Jesse Feiler 的“Sams Teach Yourself Core Data for Mac and iOS in 24 hours”,故事板在它们的开发人员界面上有很大的不同,所以不转换现有的笔尖而是将它们用于新项目是有意义的。处理视图转换方式的较大差异之一。但是,我确实冒险尝试并觉得这是值得的,因为我还处于一个更大项目的开始阶段。这样做将需要一个手动过程。Apple转换为 Storyboards 发行说明介绍了如何将故事板添加到项目中。这将为您提供一个故事板,但您现有的 xib 不会导入到故事板中。我没有这样做。我从一个新项目开始,复制了我想重用的自定义视图控制器类(.h 和 .m)。然后我继续构建我的故事板,并在有意义的时候使用界面构建器从旧项目 xib 文件中剪切和粘贴。真的不需要那么久。在您将自定义视图控制器分配给故事板中的视图控件后,您需要从选择视图转换的代码中取出 IBActions,并将它们替换为故事板转场。segues 被添加到 storyboard 中,你可以选择在你的视图控制器中添加一个 prepareForSegue 方法。