如何将基于 NIB 的项目转换为基于 Storyboard 的项目?

发布于 2024-12-17 15:59:18 字数 1455 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手心的温暖 2024-12-24 15:59:19

没有一键式的方法可以做到这一点。根据 Jesse Feiler 的“Sams Teach Yourself Core Data for Mac and iOS in 24 Hours”(Sams 在 24 小时内教自己 Mac 和 iOS 的核心数据),故事板的开发人员界面有足够的不同,因此不转换现有笔尖而是将它们用于新项目是有意义的。较大的差异之一是处理视图转换的方式。然而,我确实冒险一试,并觉得这是值得的,因为我仍接近一个更大项目的开始。这样做需要手动过程。 Apple 转换为 Storyboard 发行说明介绍了如何将 Storyboard 添加到该项目。这将为您提供一个故事板,但您现有的 xib 将不会导入到故事板中。我没有这样做。我从一个新项目开始,并复制了我想要重用的自定义视图控制器类(.h 和 .m)。然后,我继续构建我的故事板,并在有意义时使用界面生成器从旧项目 xib 文件中剪切和粘贴。确实不需要那么长时间。将自定义视图控制器分配给故事板中的视图控件后,您将需要从代码中取出选择视图转换的 IBActions 并将其替换为故事板转场。 Segues 添加到故事板中,您可以选择在视图控制器中添加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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文