Besi
Besi

Reputation: 22939

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.

Upvotes: 0

Views: 549

Answers (2)

v1Axvw
v1Axvw

Reputation: 3054

I'm certain you can. You'll have to edit the class of the File's Owner in that nib file, so that it gets linked with your custom UIViewController class.

Upvotes: 1

Besi
Besi

Reputation: 22939

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!

Upvotes: 0

Related Questions