,我在我的視圖控制器,如下編寫方法:爲「類名」無可見@interface聲明選擇「方法名」
- (IBAction)expressionEvaluation:(UIButton *)sender {
NSDictionary *testValues = [NSDictionary dictionaryWithObjectsAndKeys:@"x", 2, @"y", 3, @"z", 4, nil];
//the below line gives the error
double result = [self.brain evaluateExpression:self.brain.expression usingVariableValues:testValues];
NSString *resultString = [NSString stringWithFormat:@"%g", result];
self.display.text = resultString;
}
在我的「大腦」類我有宣佈還未完成的方法:
#import <Foundation/Foundation.h>
@interface CalculatorBrain : NSObject
- (void) pushOperand:(double)operand;
- (void) setVariableAsOperand:(NSString *)variableName;
- (void) performWaitingOperation;
- (double) performOperation:(NSString *)operation;
@property (readonly) id expression;
+ (double)evaluateExpression: (id)anExpression
usingVariableValues: (NSDictionary *)variables; //declared here
@end
...在.h和在.M:
+ (double) evaluateExpression:(id)anExpression usingVariableValues:(NSDictionary *)variables {
double result = 0;
int count = [anExpression count];
for (int i = 0; i < count; i++) {
}
return result;
}
爲什麼會出現這種「不可見@inter面對'CalculatorBrain'聲明選擇器'evaluateExpression:usingVariableValues'「錯誤?我是新來的Objective-C,但我想這意味着它沒有看到我的聲明。但我不確定它是否是語法/格式問題,因爲我對這門語言很陌生。
這樣做了!謝謝! – 2013-02-25 00:42:51
或者你可以做'[self.brain.class classMethod]' – Sebastian 2013-02-25 00:50:31