I have a weird question:
What is the pattern that the UIKit is using to figure out the right nib name for a UIViewController, when you don’t explicitly specify the nibName?
Why am I asking?
Because I thought (With a good reason) that the system will first look for the nib with the same name as the controller’s class’s.
That is, if I have a VideoViewController, the system will first look for VideoViewController.xib.
Apparently this is not the case.
I have another class, VideoView, which is a subclass of UIView. I have a nib called VideoView.xib that contains all the view hierarchy for VideoView.
When I try to run the app, it crashes immediately with setValue:ForUndefinedKey Exception.
I noticed that the key is always a key from the VideoView.xib, and not from VideoViewController.xib. That means that the system is trying to load VideoView.xib for a view controller named VideoViewController.
It seems that if the system will find a nib with a name similar the controller class name -only without the “Controller” suffix, it’ll use that nib.
I confirmed it by renaming my class to VideosViewController (With ‘s’), and everything worked just fine.
Are there any more edge conditions like this one?
Or is there a place that specify the exact algorithm?
It took me an hour to debug this one, and I don’t want to waste any more time in the future on the same problem…
Thanks!
From the documentation of UIViewController.nibName property: