最初に、私はcalculatorBrainを持っています:
@interface calculatorBrain : NSObject {
NSString *theOperator;
}
@property (assign, nonatomic) NSString *theOperator;
-(float)performOperation:(float)a andOperandB:(float)b;
@end
次に、ViewController
にリンクされた の関数button
。
ViewController.m の一部
@implementation ViewController
@synthesize result, brain;
-(IBAction)operatorPressed:(UIButton *)sender
{
if([sender.currentTitle isEqualToString:@"AC"]) {
result.text = @"0";
} else if ([sender.currentTitle isEqualToString:@"."]) {
if (0 == [result.text rangeOfString:@"."].length)
result.text = [result.text stringByAppendingString:@"."];
} else {
brain.theOperator = sender.currentTitle;
NSLog(@"%@", brain.theOperator); // return (null)
}
}
ViewController.h
@interface ViewController : UIViewController {
IBOutlet UILabel *result;
calculatorBrain *brain;
}
@property (assign, nonatomic) IBOutlet UILabel *result;
@property (strong, nonatomic) calculatorBrain *brain;
-(IBAction)digitPressed:(UIButton *)sender;
-(IBAction)operatorPressed:(UIButton *)sender;
@end
問題は、 を押した後に何も設定しないのはなぜbutton
ですか? ありがとう!