我做了每一件事,至少我试着像教程一样做每一件事,但它现在给了我 5 个错误和 1 个警告......
我刚刚开始使用 Objective-c,所以请解释你的解决方案。
这是我的代码:(在注释中标记和描述的错误)
计算器视图控制器.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
计算器视图控制器.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