IOS加法计算器

//
//  ViewController.m
//  01-加法计算器
//
//  Created by yibooo on 16/1/11.
//  Copyright © 2016年 yibooo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

// 第一个文本框
@property (nonatomic, weak) IBOutlet UITextField * num1TextField;

// 第二个文本框
@property (nonatomic, weak) IBOutlet UITextField * num2TextField;

// 计算结果
@property (nonatomic, weak) IBOutlet UILabel * resultLabel;

- (IBAction) caculate;

@end

@implementation ViewController

/*
 IBAction
 1.相当于void
 2.只有返回值类型,声明为IBAction的方法才有资格与storyboard连线

 IBOutlet
 他就是一个标识符,标示可与storyboard进行连线
 */

//计算
- (IBAction) caculate
{
//  取出文本框的内容
    NSString * num1Text = self.num1TextField.text;
    NSString * num2Text = self.num2TextField.text;

//  把字符串转换为int类型
    NSInteger result = num1Text.intValue + num2Text.intValue;

//  改变文本框的值
    self.resultLabel.text = [NSString stringWithFormat:@"%ld", (long)result];

//   退出键盘
//    [self.num1TextField resignFirstResponder];
//    [self.num2TextField resignFirstResponder];
//    只要是自己或自己的子控件呼叫出来的键盘,都可以通过这个方法来退出键盘
    [self.view endEditing:YES];
}

@end
//
//  ViewController.m
//  01-加法计算器
//
//  Created by yibooo on 16/1/11.
//  Copyright © 2016年 yibooo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

// 第一个文本框
@property (nonatomic, weak) IBOutlet UITextField * num1TextField;

// 第二个文本框
@property (nonatomic, weak) IBOutlet UITextField * num2TextField;

// 计算结果
@property (nonatomic, weak) IBOutlet UILabel * resultLabel;

- (IBAction) caculate;

@end

@implementation ViewController

/*
 IBAction
 1.相当于void
 2.只有返回值类型,声明为IBAction的方法才有资格与storyboard连线

 IBOutlet
 他就是一个标识符,标示可与storyboard进行连线
 */

//计算
- (IBAction) caculate
{
//  取出文本框的内容
    NSString * num1Text = self.num1TextField.text;
    NSString * num2Text = self.num2TextField.text;

//  把字符串转换为int类型
    NSInteger result = num1Text.intValue + num2Text.intValue;

//  改变文本框的值
    self.resultLabel.text = [NSString stringWithFormat:@"%ld", (long)result];

//   退出键盘
//    [self.num1TextField resignFirstResponder];
//    [self.num2TextField resignFirstResponder];
//    只要是自己或自己的子控件呼叫出来的键盘,都可以通过这个方法来退出键盘
    [self.view endEditing:YES];
}

@end

加法计算器源码下载
http://download.csdn.net/download/yibo_oo/9401492

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值