tags:

views:

69

answers:

2

Alright, in my rootViewController, I am able to push another viewController that I defined myself onto the screen. However, when I make any connections between that viewController and its own .h file, the program just hangs and crashes, giving me this error:

2010-06-04 15:36:13.944 pooldocfinal[11971:20b] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label1.'

That happens when i don't connect anything besides that one UILabel. Here is the code I use to declare/push the view (named balanceViewController):

    - (IBAction) pushedBalanceButton
{
    balanceViewController *controller = [[balanceViewController alloc] initWithNibName:@"balanceViewController" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

And here is the .h file of the view that I am pushing, it has only one thing in it:

#import <UIKit/UIKit.h>


@interface balanceViewController : UIViewController {

    IBOutlet UILabel *label1;

}
@end

And like I said, everything works unless I actually make a connection in Interface Builder between anything in balanceViewController.xib and balanceViewController.h (in this case, it is the one UILabel object).

+1  A: 

You should alloc a balanceViewController, not a UIViewController.

James
Good point, and I fixed that, but it still freezes just the same. what else could it be?
Suicide
A: 

I believe if you have an IBOutlet, you need to define getters/setters. That's what Key Value coding compliant means. You can do this via @property statements and @synthesize statements, or manually if you so choose.

@interface balanceViewController : UIViewController {

    IBOutlet UILabel *label1;

}

@property (nonatomic, retain) IBOutlet UILabel *label1;

@end

Then add

@synthesize label1;

to your implementation

EDIT - PS, don't forget to [label1 release] in your dealloc method

DougW
Thanks, I'll give it a shot.
Suicide
It worked perfectly, you are a god among men.
Suicide