这是代码:http: //min.us/mWdMO0n14
我是 Obj C 新手,所以我搜索了很多,但没有找到任何可以解决我的问题的东西。
我有 CalculatorViewController.h 和 .m,然后是 CalculatorBrain.h 和.m(斯坦福讲座)
在 CalculatorBrain.m 中,我有以下方法,所有变量在 CalculatorBrain 标头中定义为私有。
- (void)clearEverythingOnShakeGesture{
operand = 0;
waitingOperation = @"";
waitingOperand = 0;
}
然后在 CalculatorBrain.m 中,我将一切设置为检测抖动,如下所示。我在抖动检测上方包含了一些代码,只是为了让您有一个大致的了解。
@interface CalculatorViewController()
@property(nonatomic, retain) CalculatorBrain *brain;
@end
@implementation CalculatorViewController
@synthesize brain;
- (CalculatorBrain *)brain {
if (!brain) {
brain = [[CalculatorBrain alloc] init];
}
return brain;
}
-(BOOL)canBecomeFirstResponder{
return YES;
}
-(void)viewDidAppear: (BOOL) animated{
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake)
{
NSLog(@"SHAKE IT!");
[brain clearEverythingOnShakeGesture]; //********** not sure how to call this.
}
}
我不确定如何调用[brain clearEverythingOnShakeGesture];
,因为我收到错误“找不到类方法 +clearEverythingOnShakeGesture,默认返回类型 id”。但是,如果我将其设为类方法,则其中的变量是实例变量,这会产生另一个错误。非常感谢任何帮助。