开发者

Pushing a UIViewController doesn't work with connections

开发者 https://www.devze.com 2023-01-02 03:13 出处:网络
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,

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).


You should alloc a balanceViewController, not a UIViewController.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消