简体   繁体   English

Objective-c中的几个错误

[英]Several errors in Objective-c

I did every thing, at least I tried to do everything JUST like the tutorial, but it gives me now 5 errors and 1 warning...我做了所有的事情,至少我试着像教程一样做所有的事情,但它现在给了我 5 个错误和 1 个警告......
I am just beginning with Objective-c, so please explain your solutions.我刚开始使用 Objective-c,所以请解释您的解决方案。

Here's my code: (Errors marked and described in comments)这是我的代码:(在注释中标记和描述的错误)

CalculatorViewController.h:计算器视图控制器.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:计算器视图控制器.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

You are missing你不见了

#import "CalculatorBrain.h"

at the top of your.h file.在你的.h 文件的顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM