Matoe
Matoe

Reputation: 2758

Stop using Interface Builder

When coding iPhone applications, I've never used Interface Builder myself; thought it was too complicated and useless.

Problem is, I decided to pick up an abandoned opensourced project on GitHub which uses Interface Builder, and I can't seem to stop using it.

It seemed to be that I should start from scratch on programatically coding views, so I went to the application's Info.plist and deleted the NSMainXIBFile (or something like that) related keys.

Once I did so, the application launches, and a message is printed by the console: Applications are expected to have a root view controller at the end of application launch.

I can't seem to find the issue here; I have done:

NSArray *controllers = [NSArray arrayWithObjects:controller1, controller2, nil];
UITabBarController *tabBarController = [[UITabBarController alloc] init];

[tabBarController setViewControllers:controllers];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

Am I skipping some key step on stopping using Interface Builder or is my error at the code itself?

Upvotes: 1

Views: 226

Answers (3)

Gal
Gal

Reputation: 1582

Try

@synthesize window = _window;


_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];

And then add a subview to the window.

Upvotes: 0

Mundi
Mundi

Reputation: 80271

You need to properly assign the property window.rootViewController, not add the tab bar controller as a subview.

self.window.rootViewController = tabBarController;

Upvotes: 0

jrturton
jrturton

Reputation: 119292

You shouldn't add the tab bar controller's view to the window as a subview. You should set it as the window's root view controller instead:

window.rootViewController = tabBarController;

Upvotes: 3

Related Questions