zoukankan      html  css  js  c++  java
  • iOS 减法计算器

    一: 

    在界面上拖入相应的控件

    二: 给每个控件设置关联

    //监听按钮的点击

    - (IBAction)compute:(id)sender;

    //第一个文本输入框的值

    @property (weak, nonatomic) IBOutlet UITextField *numField1;

     

    @property (weak, nonatomic) IBOutlet UITextField *numField2;

    @property (weak, nonatomic) IBOutlet UILabel *totalLabel;

    三: 处理按钮点击事件

    - (IBAction)compute:(id)sender {

        //1 取得两个文本输入框的值

        NSString *text1 = self.numField1.text;

        NSString *text2 = self.numField2.text;

        //2 相减

        int deffernece = 0;

        int num1 = [text1 intValue];

        int num2 = [text2 intValue];

        if(num1 > num2 || num1 == num2){

            deffernece = num1 - num2;

        }else{

            //弹框

            //创建一个弹框

            //initWithTitle 标题

            //message 详细信息

            //delegate 代理

            //cancelButtonTitle 取消按钮的文字

            //otherButtonTitles 其他按钮的文字

            

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"输入的数字不合理" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];

            //2.2显示

            [alert show];

        }

        //3 把结果显示在右边的文本标签中

        _totalLabel.text = [NSString stringWithFormat:@"%d",deffernece];

        [self.view endEditing:YES];

    }

  • 相关阅读:
    PDF,仅支持英译中,可以下载后的pdf或者word版
    pip指定源安装【自用】
    【jQuery01】jQuery选择器
    【jQuery00】什么是jQuery,为什么要学jQuery,配置jQuery环境,解决冲突,大致使用流程
    什么是召回率??
    编程学习路线
    堆排序
    二叉插入排序
    每天算法一丁点(4)--递归算法应用:分书问题
    每天算法一丁点(3)--递归算法应用:半数集
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/7228709.html
Copyright © 2011-2022 走看看