viewDidLoad is never called. How can I debug my storyboard?

I'm trying to set up my iOS application so that it has two view controllers, one a MTKView and the other a GLKView. In my main storyboard I have a top level View Controller Scene, that has two Container Views. The first Container View references a subclass of GLKViewController that I have created and when the app launches my GLKViewController's viewDidLoad gets called. (So that is good!) My second Container View references a subclass of UIViewController (which I've named MetalViewController) but when the app launches MetalViewController's viewDidLoad never gets called. (So that is my problem I'm trying to figure out!)


In the storyboard editor if I click on Metal View Controller Scene the assistant editor switches to show the MetalViewController's viewDidLoad code. Also the identiy inspector shows my custom class MetalViewController. If I open the Metal View Controller Scene (by clicking on the small arrow head) immediately below I see Metal View Controller which I can select. When I do that, I see the same as when viewing the scene, ie the custom class is MetalViewController. Opening Metal View Controller and clicking on View, I see that my custom class is MTKView. In all of the above it looks to me like my MetalViewController class's code is assigned and that viewDidLoad should run. (I should also mentioned that I have tried control dragging my view controller from the storyboard to my code to connect them)


All the above is similar to the Apple provided sample source code OpenGLMetalInteroperability which has both an OpenGL view controller and a metal view controller.


Anyone have any idea why my viewDidLoad would not be called for my second view controller (the MetalViewController) but is called for my first view controller? And what do I need to do to have my second view controller's viewDidLoad called? (And subsequent draw calls)

Accepted Reply

To follow up: I figured out what was wrong and it was a doozie. I have a pretty large app that is built using multiple projects under one workspace. Each project builds and then they are all linked together. My MetalViewController class was under my Engine project. My story board is in my AppMain project. Turns out that when the linking takes place, because my MetalViewController wasn't linked to other code the linker would strip it out. (Apparently the linker doesn't care about what the story board might link to in other projects) When the app would run, there would be no warning, or anything.


To fix this, I created a subclass of my MetalViewController and included that subclass in my AppMain project. Then set my story board to have the view controller point to my subclass. And in my subclass' call to viewDidLoad I simply call [super viewDidLoad] ; which of course calls my MetalViewController's viewDidLoad.


Once that was set up my MetalViewController's functions started being being called and the graphics started drawing into the view controller. (Yeah!)


But I have to say, this is the sort of thing that Apple should be providing warnings about. The fact that I figured this out is largely dumb luck.

Replies

Some basic checks:


- checks that all views refer to the correct class (Identity Inspector)


- do an option clean build folder.


Tell what happens after those 2 steps.

To follow up: I figured out what was wrong and it was a doozie. I have a pretty large app that is built using multiple projects under one workspace. Each project builds and then they are all linked together. My MetalViewController class was under my Engine project. My story board is in my AppMain project. Turns out that when the linking takes place, because my MetalViewController wasn't linked to other code the linker would strip it out. (Apparently the linker doesn't care about what the story board might link to in other projects) When the app would run, there would be no warning, or anything.


To fix this, I created a subclass of my MetalViewController and included that subclass in my AppMain project. Then set my story board to have the view controller point to my subclass. And in my subclass' call to viewDidLoad I simply call [super viewDidLoad] ; which of course calls my MetalViewController's viewDidLoad.


Once that was set up my MetalViewController's functions started being being called and the graphics started drawing into the view controller. (Yeah!)


But I have to say, this is the sort of thing that Apple should be providing warnings about. The fact that I figured this out is largely dumb luck.