Objective-c中的几个错误

时间:2012-04-06 11:58:26

标签: objective-c xcode

我做了所有事情,至少我试图做一切就像教程一样,但它现在给了我5个错误和1个警告...
我刚刚开始使用Objective-c,所以请解释一下你的解决方案。

这是我的代码:(在评论中标记和描述的错误)

CalculatorViewController.h:

//
//  CalculatorViewController.h
//  Calculator
//
//  Created by Me on 06-04-12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CalculatorViewController : UIViewController {
    IBOutlet UILabel *display;
    CalculatorBrain *brain; // error: "Expected specifier-qualifier-list before 'CalculatorBrain':
    NSString *waitingOperation;
}

- (IBAction)digitPressed: (UIButton *)sender;

- (IBAction)operationPressed: (UIButton *)sender;

@end

CalculatorViewController.m:

//
//  CalculatorViewController.m
//  Calculator
//
//  Created by Me on 06-04-12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "CalculatorViewController.h"

@implementation CalculatorViewController 

- (CalculatorBrain *) brain { // error: "Expected ')' before 'CalculatorBrain'"
    if (!brain) { // error: "'brain' undeclared"
        brain  = [[CalculatorBrain alloc] init]; // error: "'CalculatorBrain' undeclared"
    }
    return brain;
} // warning: Control reaches end of non-void function

-(IBAction)digitPressed:(UIButton *)sender {
    if ([waitingOperation isEqualToString:@""]) {
        NSString *digit = [[sender titleLabel] text];
        [display setText:digit];
    }
    else {
        // Do calculations if everything works, now just log something to check if it works
        NSLog(@"Joepie!");
    }

}

-(IBAction)operationPressed:(UIButton *)sender {

}

- (void)dealloc {
    [super dealloc];
}

@end

1 个答案:

答案 0 :(得分:4)

你错过了

#import "CalculatorBrain.h"

位于.h文件的顶部。