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

Discussion in 'iOS Programming' started by camtorres, Sep 29, 2010.

  1. macrumors newbie

    camtorres

    Joined:
    Sep 29, 2010
    Location:
    Puerto Rico
    #1
    Hi All,

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

    Console Output

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

    Code:
    header File
    #import <UIKit/UIKit.h>
    
    @interface DashBoardViewController : UIViewController {
    	
    	UIButton *showDefaultButton;
    	
    }
    
    @property (nonatomic, retain) IBOutlet UIButton *showDefaultButton;
    
    
    - (IBAction)showDefault:(id)sender;
    
    
    Code:
    #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.
     

    Attached Files:

  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    In the nib are you sure you specified DashBoardViewController as the file's owner?
     
  3. thread starter macrumors newbie

    camtorres

    Joined:
    Sep 29, 2010
    Location:
    Puerto Rico
    #3
    Yes, I'm sure. That is why is puzzling me.
     

    Attached Files:

  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Can you post the code where you're creating the DashBoardViewController class and showing it?
     
  5. thread starter macrumors newbie

    camtorres

    Joined:
    Sep 29, 2010
    Location:
    Puerto Rico
    #5
    Sure.

    Here is the .h

    Code:
    #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

    Code:
    #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
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    There's no DashBoardViewController in that code.
     
  7. thread starter macrumors newbie

    camtorres

    Joined:
    Sep 29, 2010
    Location:
    Puerto Rico
    #7
    Sorry my mistake.

    Code:
    #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
     

    Code:
    
    #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
    
     
  8. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    I have a feeling though your MainMenu nib is referencing that nib, but is not using the class name DashBoardViewController.
     
  9. thread starter macrumors newbie

    camtorres

    Joined:
    Sep 29, 2010
    Location:
    Puerto Rico
    #9
    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?
     
  10. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    I don't see where you're instantiating tutorialViewController.
     
  11. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #11
    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.
     
  12. thread starter macrumors newbie

    camtorres

    Joined:
    Sep 29, 2010
    Location:
    Puerto Rico
    #12
    OK, i already did that. But still having the same error on the console. Even after cleaning all targets.
     
  13. thread starter macrumors newbie

    camtorres

    Joined:
    Sep 29, 2010
    Location:
    Puerto Rico
    #13
    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.
     
  14. thread starter macrumors newbie

    camtorres

    Joined:
    Sep 29, 2010
    Location:
    Puerto Rico
    #14
    Finally debuged

    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.
     

Share This Page