smily
smily

Reputation: 347

App crashes when creating Universal app with multiple XIB and single View Controller

I created a Universal window app in Xcode 4.3.3. Later I added one View Controller(UniversalRootViewController) class without XIB. Then I created two XIB files(RootViewController_iPhone, RootViewController_iPad) and then connect these iPhone XIB file RootViewController_iPhone to the UniversalRootViewController class: RootViewController_iPhone -> Select File's Owner and changed the class name in Identity Inspector as UniversalRootViewController and then connect the view as outlet to UniversalViewController and did the same thing for RootViewController_iPad.

In App Delegate , I added the following lines of code.

UniversalRootViewController *controller = nil;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    controller = [[UniversalRootViewController alloc] initWithNibName:@"RootViewController_iPad" bundle:[NSBundle mainBundle]];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
    [self.window addSubview:navigationController.view];
}
else
{
    controller = [[UniversalRootViewController alloc] initWithNibName:@"RootViewController_iPhone" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
    [self.window addSubview:controller];
}

Also I added these two key-value pairs in UniversalApp-Info.plist Main nib file base name : RootViewController_iPhone Main nib file base name (iPad) : RootViewController_iPad

When I run this application, the app creates by displaying the following error message.

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'

I connected XIB files properly to View Controller. I don't know why the app crashes. Please tell me the solution.

Upvotes: 0

Views: 158

Answers (2)

smily
smily

Reputation: 347

I solved my problem by removing the two key-value pairs of Nib files in Universal-Info.plist. Now the app works perfectly without any crash.I removed the following two lines

Upvotes: 0

Daniela Dias
Daniela Dias

Reputation: 98

You will have to set the view outlet in the File's Owner to each view in the XIB file: - Go to one of the XIB file (iphone for example) and drag with the left mouse button from the file owner to the top view below in objects. Select view. - Do the same for the other XIB file

Upvotes: 1

Related Questions