问题描述
我正在使用故事板(这是全新的!)。
I'm using storyboard (this is completely new!).
如何使用storyboard选项导入现有的xib文件并将它们集成到一个文件中?
How do I import my existing xib files and integrate them onto a single file, using the storyboard option?
推荐答案
没有一键式方法可以做到这一点。根据Jesse Feiler的Sams在24小时内为Mac和iOS教授自己的核心数据,故事板在他们的开发人员界面中有不同之处,因为不转换现有的笔尖而是将它们用于新项目是有意义的。处理视图转换的方式之一存在较大差异。然而,我确实采取了暴跌,并认为这是值得的,因为我仍然接近一个更大的项目的开始。这样做需要手动过程。 Apple 介绍了如何将Storyboard添加到项目中。这将为您提供故事板,但您现有的xib将不会导入故事板。我没有这样做。我从一个新项目开始,并复制了我想重用的自定义视图控制器类(.h和.m)。然后我继续构建我的故事板,并在有意义的时候使用界面构建器剪切并粘贴旧项目xib文件。这真的不需要那么久。将自定义视图控制器分配给控制故事板中的视图后,您将需要从代码中取出IBActions,选择视图转换并将其替换为故事板segue。在故事板中添加segue,您可以选择在视图控制器中添加prepareForSegue方法。可选的prepareForSegue方法用于完成源视图控制器中的任何操作,并在转换之前设置目标视图控制器。
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 Notes addresses 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.
这篇关于如何将基于NIB的项目转换为基于故事板的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!