this class is not key value coding-compliant

Discussion in 'iOS Programming' started by collinssol, May 20, 2010.

  1. collinssol macrumors newbie

    Joined:
    Oct 15, 2009
    #1
    ok i know what this means but i have exhausted myself trying to find where the error is at. I have an app that displays a login page. a proper login loads a view where a task is picked from the uipicker. I can then load another view based on that . Right now i am loading my SearchViewController and if i have nothing connected it loads but once i connect my UITextField i get:

    Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ActionsViewController 0x192090> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tagNum.'

    I cant seem to find where the break is. NOw i did reuse the code to load the last view.
    Code:
    - (void) fliptoactions{
    	ActionsViewController *aSecondView = [[ActionsViewController alloc] initWithNibName:@"ActionsViewController" bundle:nil];
    	[self setActionsViewController:aSecondView];
    	[aSecondView release];
    	
    	[UIView beginAnimations:nil context:NULL];
    	[UIView setAnimationDuration:2.0];
    	[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
    	[mainViewController.view removeFromSuperview];
    	[self.window addSubview:[actionsViewController view]];
    	[UIView commitAnimations];
    }
    
    - (void) fliptosearch{
    	ActionsViewController *aSecondView = [[ActionsViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
    	[self setActionsViewController:aSecondView];
    	[aSecondView release];
    	
    	[UIView beginAnimations:nil context:NULL];
    	[UIView setAnimationDuration:2.0];
    	[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
    	[mainViewController.view removeFromSuperview];
    	[self.window addSubview:[actionsViewController view]];
    	[UIView commitAnimations];
    }
    
    Code:
    - (IBAction)doAction:(id)sender {
    	ivTechAppDelegate *mainDelegate = (ivTechAppDelegate *)[[UIApplication sharedApplication] delegate];
    	
    	if([pickedAction isEqualToString:@"Search Computers"])
    	{
    		[mainDelegate fliptosearch];
    	}
    }
    Do i need to have a view controller declared for every single view i want to load. My app will have a little over a dozen xib files so that seems a bit over kill
     
  2. TiberiusXavier macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #2
    What does your method setActionsViewController actually do?

    Is there no way to use the standard frameworks of the tab control or navigation control?

    If you are in danger of exhausting memory, consider implementing didReceiveMemoryWarning and viewDidUnload.
     
  3. collinssol thread starter macrumors newbie

    Joined:
    Oct 15, 2009
    #3
    little more info

    This is my first big application as in needing more then one xib. The first xib is to take a user name and password. Based on that i load the next xib which populates a uipicker with all the actions that user is allowed to perform. They roll to an action then hit a load button and the xib for that action is loaded. This third xib is a search page to find computers based on criteria. If i do not connect any of the UI elements the view loads fine. Once i connect the textfield and button to their respective outlets i get the above error.
     
  4. TiberiusXavier macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #4
    If you want a view to load another view dynamically, you should consider using the UINavigationController class. UINavigationController provides a method to push a view and navigates down a level.
    Code:
        // Setup Search Navigation Controller:
        searchNavigationController = [[UINavigationController alloc] init];
        searchNavigationController.title = @"Search";
        ActionsViewController * instanceSearchViewController = [[ActionsViewController alloc] initWithNibName: @"SearchViewController" bundle: [NSBundle mainBundle]];
        tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemSearch tag: 0];
        searchNavigationController.tabBarItem = tabBarItem;
        [tabBarItem release];
        [searchNavigationController pushViewController: instanceSearchViewController animated: NO];
        [instanceSearchViewController release];  // Instance retained by navigation controller.
    
    Then in your search controller implementation, you can push the results view controller:
    Code:
    [self.navigationController pushViewController: resultsListViewController animated: YES];
    
    If the first xib is more of a login window, you may want to not have that as you main xib and instead load it up as modal.

    If you want to be able to switch between different views like the buttons on the bottom of the iPod app, you would want the UITabBarController.

    Code:
        // Add UITabBarController * tabBarController; to your .h file.
    
    - (void)applicationDidFinishLaunching: (UIApplication *)application
    {    
        // Setup your ActionsViewConroller and SearchViewController.
        .
        .
        .
    
        tabBarController = [[UITabBarController alloc] init];
        tabBarController.viewControllers = [NSArray arrayWithObjects: instanceActionsViewController, instanceSearchViewController, nil];
        tabBarController.delegate = self;
        [window addSubview: tabBarController.view];
    
        [instanceActionsViewController release]; // Tab bar controller retains.
        [instanceSearchViewController release]; // Tab bar controller retains.
    
        .
        .
    }
    

    All these separate controllers can be contained in different xib files (in fact that is recommended for memory utilization).
     
  5. collinssol thread starter macrumors newbie

    Joined:
    Oct 15, 2009
    #5
    thats a great idea. Could put the main 4 tasks on the tab bar with a more button. I might just need to start from scratch. Guess i have a lot to learn about app navigation. I will try my best to implement the UITabBarController and i will post back if i have major problems with it. Thanks
     
  6. collinssol thread starter macrumors newbie

    Joined:
    Oct 15, 2009
    #6
    ok i set up a new project with tabview controllers but i am still geting *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x11b1d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key usern.' when i try and hook up my textfields.

    I have two tabcontrollers one loads the login xib and the other controls the view that will have all the different tabs for actions. i created a new view with a controller .h and .m file. I then set this as the xib to load in the logintabcontroller.

    I load it like so

    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        user_name = @"_";
        // Add the tab bar controller's current view as a subview of the window
        //[window addSubview:tabBarController.view];
    	[window addSubview:loginController.view];
        [window makeKeyAndVisible];
    	
    	return YES;
    }
    This works great and does what i want it to do. I go into the applogin.xib file and connect all my outlets in file's owner and i get the error above. What i want is when the login button is pressed the credentials are checked with code i already have and then the other tab controller be loaded dismissing the login screen. Any advice would be appreciated.
     

Share This Page