Ios – this class is not key value coding-compliant for the key view

iosiphoneobjective cxcode

i´m very new to xcode… a made an app (simple calculator) work´s pretty good (on simulator and device).
When i set the main interface in the summary options from Target, i get the following error when starting the simulator:

2012-04-14 12:17:27.123 CalcTest[27550:f803] * Terminating app due
to uncaught exception 'NSUnknownKeyException',

reason:
'[<UIApplication 0x6a14650> setValue:forUndefinedKey:]: this class is
not key value coding-compliant for the key calculatorScreen.'

* First throw call stack: (0x12db022 0x18f8cd6 0x12daee1 0xcc2022 0xc33f6b 0xc33edb 0xc4ed50 0x53671a 0x12dcdea 0x12467f1 0x53526e
0x536eb7 0x313ce1 0x313ff8 0x31317f 0x322183 0x322c38 0x316634
0x27fcef5 0x12af195 0x1213ff2 0x12128da 0x1211d84 0x1211c9b 0x312c65
0x314626 0x1bad 0x1b15 0x1) terminate called throwing an
exception(lldb)

to find the problem, i started a new view based project.

Run the empty new project on the simulator –>works,

But when I set the main interface, to ViewController, in the summary –>the Simulator crash with

2012-04-14 12:11:17.492 crash[27494:f803] * Terminating app due to uncaught
exception 'NSUnknownKeyException', reason:

'[<UIApplication 0x6a6f4b0> setValue:forUndefinedKey:]: this class is
not key value coding-compliant for the key view.'
* First throw call stack:

(0x13c7022 0x1558cd6 0x13c6ee1 0x9bf022 0x930f6b 0x930edb 0x94bd50
0x23371a 0x13c8dea 0x13327f1 0x23226e 0x233eb7 0x10ce1 0x10ff8 0x1017f
0x1f183 0x1fc38 0x13634 0x12b1ef5 0x139b195 0x12ffff2 0x12fe8da
0x12fdd84 0x12fdc9b 0xfc65 0x11626 0x1d4d 0x1cb5) terminate called
throwing an exception

is there a solution for the problem?

Best Answer

If you have a control in your nib (xib file) that is linked to a property (IBOutlet) or method (IBAction) in your view controller, and you have either deleted or renamed the property or method, the runtime can't find it because it has been renamed and therefore crashes.

In your case, you have set the Main Interface property of the project to your ViewController.nib. This is a problem because the only nibs that should be used as Main Interface should have UIWindows in them and the File Owner in that nib should be set to the AppDelegate. The UIWindow in the nib should be linked to the File Owner's (AppDelegate) window property. Because you set that with a nib without the traits the runtime was looking for, it gives you this error.

The solution is to leave the Main Interface blank as you do not have to set up UIWindows manually anymore.