UrK
UrK

Reputation: 2300

Replacing storyboard with XIB

How can I replace storyboard with XIB?

While trying to create dynamically views and their controllers, I lost all advantages of the new storyboard. Now, when trying to remove it from the project, I created a new XIB with its own controller and replaced it in project settings:
enter image description here
Now, when trying to run the application, it crashes and the log shows me the following:

2012-04-08 14:50:16.567 Bazaart[11340:15203] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x8c15c20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'

Here is the code of: UIRootWindow:

#import <UIKit/UIKit.h>
@interface UIRootWindow : UIViewController
@end

And its corresponding implementation:

#import "UIRootWindow.h"
@implementation UIRootWindow

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
}
- (void)viewDidUnload {
    [super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
@end

EDIT:
I've the window as suggested by Phillip (see below). But... the way I did it is not the best, it seems. Am I doing it right?

UIRootWindow *wnd = [[UIRootWindow alloc] init];
[wnd view];
[self setWindow:wnd.window];

Upvotes: 3

Views: 2822

Answers (2)

Stephen
Stephen

Reputation: 532

When your app is starting, each controller in your XIB is created based on the name of the class you've set. Then each property you've wired visually is set using KVC. The error is telling you that somewhere along this process, the 'view' property is incorrect.

I can think of two reasons why this might be happening:

  • You don't have the right class set for your ViewController or another object in your XIB (in the 'Identity Inspector')
  • You haven't correctly wired the connections. (In the 'Connections Inspector')

Either way, you can do a quick run-through of the settings in your XIB noting where the property 'view' is connected.

Upvotes: 0

Phillip Mills
Phillip Mills

Reputation: 31016

Don't put anything into the Main Interface field. Instead, load your top-level controllers in the app delegate's didFinishLaunchingWithOptions: method and set the window's root controller there.

Application start-up assumes that a xib mentioned there has a File's Owner that is a UIApplication. (Older templates used to do that and some sample projects still do.)

Upvotes: 7

Related Questions