I have a problem in AppDelegate, when run the app I get this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<UIApplication 0x856c820> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key view.'
This is the code of AppDelegate.h
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
//UINavigationController *navigationController;
}
@property (strong, nonatomic) UIWindow *window;
@property (copy, nonatomic) ViewController * viewController;
@property (copy, nonatomic) UINavigationController * navigationController;
@end
This is the code of AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *rootMenu;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
rootMenu= [[RootViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
rootMenu = [[RootViewController alloc]initWithNibName:@"ViewController_iPad" bundle:nil];
}
self.navigationController =[[UINavigationController alloc]initWithRootViewController:rootMenu];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
What can I do to resolve this error? I have rewritten the RootViewController, throwing in the trash the old one, but the problem remains the same.Thanks in advance
You can fix the error by breaking the connection that is causing the problem. Simply click the X to delete the outlet. Then you can go back to the View Controller and simply recreate the connection. Just hold the control key and drag and drop the mouse pointer to the outlet you want to connect.
Key-value coding is a mechanism enabled by the NSKeyValueCoding informal protocol that objects adopt to provide indirect access to their properties. When an object is key-value coding compliant, its properties are addressable via string parameters through a concise, uniform messaging interface.
The type qualifier IBOutlet is a tag applied to an property declaration so that the Interface Builder application can recognize the property as an outlet and synchronize the display and connection of it with Xcode. An outlet is declared as a weak reference ( weak ) to prevent strong reference cycles.
This usually happens when an Interface Builder or Storyboard connection hasn't properly been made. Sometimes you'll make a connection, and then delete the code that the connection was made to. Interface Builder still has a reference to the code, which causes the key/value compliant run time error. You can also get this error if you haven't assigned the proper class to a view controller. If you've written code for a particular view controller, be sure to set the class appropriately in Interface Builder for that View Controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With