开发者

Sub-classed View Controller gets error 'not key value coding-compliant'

I have been trying to solve this bug for 2 days straight and can't seem to find the problem.

I sub-classed a standard ViewController like so:

@interface ToolbarVC : UIViewController {
 IBOutlet UIButton* button1;
 IBOutlet UIButton* button2;
 IBOutlet UIButton* button3;
 IBOutlet UIButton* button4;
}
@property(nonatomic, retain) IBOutlet UIButton* button1;
@property(nonatomic, retain) IBOutlet UIButton* button2;
@property(nonatomic, retain) IBOutlet UIButton* button3;
@property(nonatomic, retain) IBOutlet UIButton* button4;

-(IBAction) button1Pressed:(id)sender;
-(IBAction) button2Pressed:(id)sende开发者_如何学运维r;
-(IBAction) button3Pressed:(id)sender;
-(IBAction) button4Pressed:(id)sender;

@end

In interface builder, I wired up all the buttons to the File's owner, like normal.

In the ToolbarVC Identity inspector, under class identity, I changed the File's Owner class name to 'ToolbarVC'.

In my AppViewController, I instantiate the class like this:

ToolbarVC* tbvc = [[ToolbarVC alloc] init];
photoToolbarVC = tbvc; // this is my class variable
[self.view addSubview:tbvc.view];

The ToolbarVC inits, and in it's viewDidLoad method sets the button names and sizes properly.

However, if I try to click the buttons it crashes with 'EXC_BAD_ACCESS'. IF I try to animate the toolbar into the view like this:

[UIView beginAnimations:@"addToolbars" context:nil];
[UIView setAnimationDuration:kFadeDuration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[photoToolbarVC.view setCenter:CGPointMake(512, 200)];
[UIView commitAnimations];

It gives me this error:

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

I've searched for two days and tried several ways to fix it, including initWithNibName:@"ToolbarVC".

What's interesting is if I don't animate it into the view, it displays, with the buttons properly named and sized (this happens in the ToolbarVC viewDidLoad method when it's created). Only when I try to animate it, or click a button, it crashes.


Hated. I found it. Turns out the reference was being released and could be accessed. Two days over a release statement. To make things worse, I find it an hour after I post here. :(

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜