PDA

View Full Version : NSUnknownKeyException reason: class is not key value coding-compliant for the key




camtorres
Sep 29, 2010, 08:15 PM
Hi All,

I'm new to the iphone sdk. And having some problems debugging this error:

Console Output
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x5f21600> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key showDefaultButton.'
***


What i'm trying to achieve is to retrieve a modal view thru the use of a button.


header File
#import <UIKit/UIKit.h>

@interface DashBoardViewController : UIViewController {

UIButton *showDefaultButton;

}

@property (nonatomic, retain) IBOutlet UIButton *showDefaultButton;


- (IBAction)showDefault:(id)sender;




#import "DashBoardViewController.h"
#import "TutorialViewController.h"


@implementation DashBoardViewController

@synthesize showDefaultButton;


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (IBAction)showDefault:(id)sender {
TutorialViewController *tutorialView = [[TutorialViewController alloc] init];
[self presentModalViewController:tutorialView animated:YES];
}



- (void)dealloc {
[TutorialViewController release];
[showDefaultButton release];
[super dealloc];
}

@end

I have created and connected the nib files. When ever I connect the showDefaultButton I get the previous mentioned error. Even when i'm specifying the class that I created to handle this event on the class identity.



kainjow
Sep 29, 2010, 09:45 PM
In the nib are you sure you specified DashBoardViewController as the file's owner?

camtorres
Sep 29, 2010, 11:24 PM
In the nib are you sure you specified DashBoardViewController as the file's owner?

Yes, I'm sure. That is why is puzzling me.

kainjow
Sep 29, 2010, 11:34 PM
Can you post the code where you're creating the DashBoardViewController class and showing it?

camtorres
Sep 29, 2010, 11:40 PM
Can you post the code where you're creating the DashBoardViewController class and showing it?

Sure.

Here is the .h

#import <UIKit/UIKit.h>
@class TutorialViewController;

@interface iListingAppDelegate : NSObject <UIApplicationDelegate,UITabBarControllerDelegate>

{
UIWindow *window;
UITabBarController *tabBarController;
TutorialViewController *tutorialViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) TutorialViewController *tutorialViewController;


and the .m


#import "iListingAppDelegate.h"
#import "TutorialViewController.h"

@implementation iListingAppDelegate

@synthesize window;
@synthesize tabBarController;
@synthesize tutorialViewController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[window addSubview:tabBarController.view];
[window addSubview:tutorialViewController.view];
[window makeKeyAndVisible];


return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

}


- (void)applicationWillTerminate:(UIApplication *)application {

}


#pragma mark -
#pragma mark UITabBarControllerDelegate methods

/*
// Optional UITabBarControllerDelegate method.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}
*/

/*
// Optional UITabBarControllerDelegate method.
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
}
*/


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {

}


- (void)dealloc {
[tutorialViewController release];
[tabBarController release];
[window release];
[super dealloc];
}

@end

dejo
Sep 29, 2010, 11:44 PM
Sure.

<code clipped>
There's no DashBoardViewController in that code.

camtorres
Sep 29, 2010, 11:49 PM
There's no DashBoardViewController in that code.

Sorry my mistake.

#import <UIKit/UIKit.h>
@class DashBoardViewController;

@interface iListingAppDelegate : NSObject <UIApplicationDelegate,UITabBarControllerDelegate>

{
UIWindow *window;
UITabBarController *tabBarController;
DashBoardViewController *tutorialViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) DashBoardViewController *tutorialViewController;

@end





#import "iListingAppDelegate.h"
#import "DashBoardViewController.h"

@implementation iListingAppDelegate

@synthesize window;
@synthesize tabBarController;
@synthesize tutorialViewController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[window addSubview:tabBarController.view];
[window addSubview:tutorialViewController.view];
[window makeKeyAndVisible];


return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

}


- (void)applicationWillTerminate:(UIApplication *)application {

}


#pragma mark -
#pragma mark UITabBarControllerDelegate methods

/*
// Optional UITabBarControllerDelegate method.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}
*/

/*
// Optional UITabBarControllerDelegate method.
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
}
*/


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {

}


- (void)dealloc {
[tutorialViewController release];
[tabBarController release];
[window release];
[super dealloc];
}

@end

kainjow
Sep 29, 2010, 11:53 PM
I have a feeling though your MainMenu nib is referencing that nib, but is not using the class name DashBoardViewController.

camtorres
Sep 29, 2010, 11:55 PM
I have a feeling though your MainMenu nib is referencing that nib, but is not using the class name DashBoardViewController.

Yes indeed. My MainMenu nib has no reference to a class. Do i have to add the reference on IB to the MainMenu FileOwner class to DashBoardViewController?

dejo
Sep 29, 2010, 11:59 PM
I don't see where you're instantiating tutorialViewController.

kainjow
Sep 30, 2010, 12:01 AM
Your main menu nib probably has the UIViewController instance, correct? If so, you need to select that and give it the name of your custom class.

camtorres
Sep 30, 2010, 12:04 AM
Your main menu nib probably has the UIViewController instance, correct? If so, you need to select that and give it the name of your custom class.

OK, i already did that. But still having the same error on the console. Even after cleaning all targets.

camtorres
Sep 30, 2010, 12:21 AM
Originally Posted by kainjow
Your main menu nib probably has the UIViewController instance, correct? If so, you need to select that and give it the name of your custom class.

I have a DashBoardView.xib connected to the DashBoardViewController class. Is that what you meant when you said the main nib? Because my main nib file is DashBoardWindowController.xib and is connected to the UIApplicaction class.

camtorres
Sep 30, 2010, 03:01 AM
OK.. so here is what i was doing wrong.

I'm using a tabbar to present the view where the button resides. I had added the proper classes to the class identity section. But missed to used the class name on the tab bat item class identity section. So the set value was not being read before. Now it compiles and runs without problems.