Search code examples
xcodeuitableviewuiviewnibconceptual

ViewController vs. without Nib file


When I create a UIViewController in Xcode I can decide to add a nib file. Assuming I don't add the nib file at this time. Can I simple add a nib file later and give it the same name as the ViewController?

I am asking this because I currently have a tableview with a certain background color. However, when the view is displayed it looks like the generic UITableView is used instead.

So it is like my nib file is ignored, in fact, when I delete the nib file, it still works the same, but without the background color.


Solution

  • I figured it out what my nib file was ignored. The problem was that I did not instantiate my ViewController myself bug I defined it in IB by adding a NSObject to my storyboard and setting its class to my class.

    However, like this the object is simply alloc] init]'ed but to load the nib, it has to be allocated like this:

        self.myVC = [[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];
    

    As soon as I do this the nib is loaded and I can configure my UITableView in Xcode. Hooray!