this class is not key value coding-compliant for t

2019-07-16 14:13发布

问题:

I am relatively new to programming and I'm using Xcode to code a very simple animation.

Here is my BuildingViewController.h:

#import <UIKit/UIKit.h>

@interface BuildingViewController : UIViewController {

}
@property (nonatomic, retain) IBOutlet UIButton * buttonTarget;

- (IBAction)performRotate:(id)sender;
//- (void)setValue:(id)value forKey:(NSString *)performRotate;

@end

And Here Is My BuildingViewController.m

import "BuildingViewController.h"

@interface BuildingViewController ()

@end

@implementation BuildingViewController

//@synthesize image;


- (void)viewDidLoad
{
//    [image setAlpha:0];
//  [self startAnimation];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)performRotate:(id)sender {

    [UIView animateWithDuration:1.0 animations:^{
    CGAffineTransform previousTransformation = self.buttonTarget.transform;
    CGAffineTransform newRotationTransformation = CGAffineTransformMakeRotation(90.0f * (M_PI / 180.0f));
    CGAffineTransform newTransformation = CGAffineTransformConcat(previousTransformation, newRotationTransformation);
    self.buttonTarget.transform = newTransformation;
}];

}

@end

And the error I'm getting looks like this:

2012-10-11 10:08:47.676 graphics1[27608:c07] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key PerformRotate.' * First throw call stack: (0x1c8e012 0x10cbe7e 0x1d16fb1 0xb78711 0xaf9ec8 0xaf99b7 0xb24428 0x2300cc 0x10df663 0x1c8945a 0x22ebcf 0xf3e37 0xf4418 0xf4648 0xf4882 0x43a25 0x43dbf 0x43f55 0x4cf67 0x10fcc 0x11fab 0x23315 0x2424b 0x15cf8 0x1be9df9 0x1be9ad0 0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44 0x1c33e1b 0x117da 0x1365c 0x259d 0x24c5) libc++abi.dylib: terminate called throwing an exception

Do I have to tamper with the BuildingAppDelegate.h or .m?

回答1:

Check your XIB/Storyboard. Chances are your - (IBAction)performRotate:(id)sender method was originally named - (IBAction)PerformRotate:(id)sender and the latter one is the one connected in IB. When you change the method name, you got to reconnect it in the XIB/Storyboard or it'll call your old method, which no longer exists.