[英]Several errors in Objective-c
我做了所有的事情,至少我試着像教程一樣做所有的事情,但它現在給了我 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
你不見了
#import "CalculatorBrain.h"
在你的.h 文件的頂部。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.