从 XIB(aka NIB)文件移动到 Main.storyboard 并且不调用 init 方法

Moving from XIB (aka NIB) file to Main.storyboard and the init method is not called

我一直想推出一款文字游戏,所以 2 周前我购买了一个应用程序模板。

不幸的是,购买的源代码使用 XIB 文件(而不使用 ARC)- 我想改变它。

所以我添加了一个 Main.storyboard 文件并将第一个 XIB 文件的内容复制到其中。我按住 Ctrl 键拖动属性,设置 "Is Initial View Controller" 复选框并将 "Main" 指定为 "Main storyboard file base name"(这里是 fullscreen):

不幸的是,我在调试器中看到,位于 HomeViewController.m 的 init 方法中的代码不是 运行(这里是 fullscreen):

所以我的问题是:如何重命名 init 方法,使其再次成为 运行 - 当使用故事板而不是 NIB 文件时?

我想我的问题对于经验丰富的 iOS 程序员来说很简单,但我自己找不到答案(例如在 Apple 的 View Controller Programming Guide for iOS 中)。

找到从 XIB 转移到故事板的解决方案:

  • 将代码从init移动到initWithCoder:

  • 并调整 Core Data 代码,因为 initWithCoder:application:didFinishLaunchingWithOptions: 之后被调用(而 init 之前被调用)