'class is not key value coding-compliant for the key navigationBar

I have added a UINavigationbar and UIscrollView to UIView(SecondView).When I click a button in firstView it should take me to secondView. On button click :

 SecondView *secondview=[[SecondView alloc]initWithNibName:@"SecondView" bundle:nil];
 [self presentModalViewController: secondview animated:NO]; //error at this line 
 [secondview release];

In the secondView.h

@property(nonatomic,retain)IBOutlet UINavigationBar *navigationBar;
@property(nonatomic,retain)IBOutlet UIScrollView *testscroll;

SecondView.m:

@synthesize navigationBar,testscroll;

But Im getting error like :

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: SecondView setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navigationBar.

My secondView.xib is like this :

Couldnot understand where Im going wrong?



Solution 1:[1]

I solved it myself. I was wrong with nothing.Everything was OK. I have added a new view and made the same connections and got it.Don't know why this happens regularly in xcode.

Solution 2:[2]

This error generally comes when you have created an outlet in your xib and then by mistake (or knowingly) you have deleted that iboutlet object, or vice versa.

So check your xib's iboutlet connections carefully.

Solution 3:[3]

Check the spelling:

@property(nonatomic,retain)IBOutlet UINavigationBar *navigationBar;

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: SecondView setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navigationbar.

Note the difference of navigationBar and navigationbar, it's case sensitive.

Solution 4:[4]

you can presenting ModelViweController With navigationbar like this way:-

SecondView *objSecondView = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:objSecondView];

// add navigation bar image at hear

     UIImage *image = [UIImage imageNamed:@"nav_launcher.png"];
                [navbar.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
     navbar.navigationBar.tintColor=[UIColor whiteColor];

     [self presentModalViewController:navbar animated:YES];

and you can Push One View to Another View like:-

SecondView *objSecondView =[[SecondView alloc]initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:objSecondView animated:YES];

NOTE

Some time its error occurs because of we are putting wrong Nib name at this line of code : initWithNibName:@"SecondView" bundle:nil];

UPDATE

no need to add navbar tin image at SecondViewcontroller you can add all stuff hear like barbuttonItem, tincolor , navigatin BackgroudnColor ect.

Solution 5:[5]

pushViewController: is used to push a UIViewController. It looks like SecondView is a UIView, not a UIViewController.

Solution 6:[6]

If you face this problem again, try to: select File's Owner then click on the "Connection Inspector" (upper on the top of right pane), you will see all the outlets. Look for any sign like this (!) you will find it on the small circle which indicates a missing outlet, all you have to do is linking it properly or remove the outlet.

Solution 7:[7]

  1. For erroneous case Rakesh provided correct answer (outlet was deleted - need accurately check your xib's / storyboards) with small addition: it might be also caused by renaming outlet by simply "Find&Replace". In such case the outlet is re-named everywhere in sources, but not in storyboard. In such case make sure you accurately renamed the outlet in storyboards too, e.g.:

    grep -r --include "*.storyboard" navigationBar .

  2. Than everything looks to be ok: XCode caching your xib's, to fix the behavior:
    • clean build
    • remove app from device/simulator
    • restart the app Restart simulator might be also necessary (for me never was required for device)

Solution 8:[8]

I think you have not connect some object to the File's Owner in that UIViewController's xib.

Check one time my friend.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sindhia
Solution 2 halfer
Solution 3 Community
Solution 4
Solution 5 Costa Walcott
Solution 6
Solution 7 Tamara
Solution 8 halfer