Search code examples
iosuistoryboardxibnibxcode-storyboard

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


I've always wanted to launch a word game, so 2 weeks ago I have purchased an app template.

Unfortunately, the purchased source code uses XIB files (and does not use ARC) - and I would like to change that.

So I have added a Main.storyboard file and have copied the contents of the first XIB file into it. I have ctrl-dragged the properties, set the "Is Initial View Controller" checkbox and specified "Main" as "Main storyboard file base name" (here fullscreen):

Xcode

Unfortunately, I see in debugger, that the code which was located in the init method of the HomeViewController.m is not run (here fullscreen):

Xcode

So my question is: how to rename the init method, so that it is run again - when using storyboard instead of NIB files?

I guess my question is very simple for seasoned iOS programmers, but I couldn't find the answer myself (for example in the View Controller Programming Guide for iOS by Apple).


Solution

  • Found solution for moving from XIB to storyboard:

    • Move the code from init to initWithCoder:

    • And adapt the Core Data code, because initWithCoder: is being called after the application:didFinishLaunchingWithOptions: (while the init was called before)