虽然还有很多不懂的,但是以后这些应该都能理解
#import "ViewController.h"
@interface ViewController ()
//这里开始
{
long long sum;
double a;
long long b;
NSString *dengyu;//=号
BOOL isoption;//判断是否点击操作符
} //定义全局变量
@property (weak, nonatomic) IBOutlet UILabel *show;
//这是显示
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)number0:(UIButton *)sender //按钮 0-9 事件
{
NSInteger number = sender.tag;
NSLog(@"%ld",number);
if(isoption == YES)
{
sum = sender.tag-100;
isoption = NO;
}
else
{
sum =( sender.tag -100)+[self.show.text longLongValue]*10; //运算语句
//从文本框的内容乘10加上刚输入的数值。
}
self.show.text=[NSString stringWithFormat:@"%lld",sum];
}
/**
//清除按钮事件
*/
- (IBAction)cleam:(UIButton *)sender //清零
{
[email protected]"0";
}
- (IBAction)dengyu:(UIButton *)sender
{
switch (sender.tag) {
case 200:
{
NSLog(@"你点击了等操作");
if ([dengyu isEqualToString:@"+"])
{
long long result = a +[self.show.text longLongValue];
self.show.text = [NSString stringWithFormat:@"%lld",result];
}
else if ([dengyu isEqualToString:@"-"])
{
long long result = a - [self.show.text longLongValue];
self.show.text=[NSString stringWithFormat:@"%lld",result];
}
else if ([dengyu isEqualToString:@"*"])
{
long long result = a *[self.show.text longLongValue];
self.show.text = [NSString stringWithFormat:@"%lld",result];
}
else if ([dengyu isEqualToString:@"/"])
{
double result = a /[self.show.text longLongValue];
self.show.text = [NSString stringWithFormat:@"%g",result];
}
}
break;
case 201:
{
NSLog(@"你点击了乘操作");
a=[self.show.text longLongValue];
dengyu [email protected]"*";
isoption = YES;
}
break;
case 202:
{
//NSLog(@"你点击了除操作");
a=[self.show.text longLongValue];
dengyu [email protected]"/";
isoption = YES;
}
break;
case 203:
{
//NSLog(@"你点击了减操作");
a=[self.show.text longLongValue];
dengyu [email protected]"-";
isoption = YES;
}
break;
case 204:
{
// NSLog(@"你点击了加操作");
a=[self.show.text longLongValue];
dengyu = @"+";
isoption = YES;
}
break;
default:
break;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end