对于关键的PerformRotate,此类不符合键值编码

Nik*_*how 2 xcode key objective-c ios

我对编程比较陌生,而且我正在使用Xcode编写一个非常简单的动画.

这是我的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
Run Code Online (Sandbox Code Playgroud)

这是我的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
Run Code Online (Sandbox Code Playgroud)

而我得到的错误看起来像这样:

2012-10-11 10:08:47.676 graphics1 [27608:c07] *由于未捕获的异常'NSUnknownKeyException'终止应用程序,原因:'[setValue:forUndefinedKey:]:此类不是密钥值编码兼容的密钥PerformRotate ".*第一掷调用堆栈:(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:终止调用抛出异常

我是否必须篡改BuildingAppDelegate.h.m

yuf*_*yuf 11

检查您的XIB /故事板.机会- (IBAction)performRotate:(id)sender最初是您的方法命名的- (IBAction)PerformRotate:(id)sender,后者是IB中连接的方法.当您更改方法名称时,您必须在XIB/Storyboard中重新连接它,否则它将调用您不再存在的旧方法.

  • +1很好的答案!@NikitaJerschow如果这样可以解决问题,请考虑通过单击复选标记的灰色轮廓来接受此答案.这将告诉其他人您不再需要改进的解决方案,并在Stack Overflow上为您赢得全新的徽章. (2认同)