Matt Delves
Matt Delves

Reputation: 1605

iOS add rootViewController to window causes delegate not found error

I'm creating an application that first loads a settings screen which displays a series of text fields and labels asking the user for input. This is all working fine.

What I then want to do is once this data has been input, it comes up with the main application interface.

What is happening though is that when I'm telling the application delegate to load the main view, it says that the viewController isn't key value complaint for the key delegate.

The code I'm using to create the viewController is:

CustomViewController *viewController = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];
self.window.rootViewController = viewController;

If anyone thinks that UIWindow doesn't have a rootViewController property, please check the documentation. That's what I did, and it does have one.

Any help with figuring this out would be greatly appreciated.

For those that like full debug info, this is what I get from xcode.

2011-06-18 15:03:15.474 Some App[15596:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CustomViewController 0x53368b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'

Thanks,

Matt.

Upvotes: 1

Views: 1400

Answers (2)

Cocoanetics
Cocoanetics

Reputation: 8247

The rootViewController property was only recently introduced and might not be available on devices running an older version of iOS.

You want to have a UINavigationController as the root view controller of your application and subsequent pages you simply push onto it. If you don't want animation, then do animate:NO. If you don't need a navigation bar, then hide that as well.

It is generally preferable to use one of the existing container view controllers over swapping them out yourself.

Upvotes: 0

Matthias Bauch
Matthias Bauch

Reputation: 90117

Most likely you try to use delegate somewhere in your xib file, but it doesn't exist in your CustomViewController class.

Check the connections in your nib file and remove the one that connects to the non existing delegate.

Upvotes: 1

Related Questions