起初,我有一个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)
}
}
视图控制器.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
?谢谢!