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];

    }

  • 相关阅读:
    This is very likely to create a memory leak. Stack trace of thread错误分析
    spring boot 2.0 neo4j 使用
    造个简单的轮子倒是不难,但可用性健壮性高到qt这样全世界都在用,就几乎不可能了
    0xC0000005;Access Violation(栈区空间很宝贵, linux上栈区空间默认为8M,vc6下默认栈空间大小为1M)
    Object::connect: Cannot queue arguments of type 'QMap<QString,QString>'(要使用qRegisterMetaType<StringMap>进行注册)
    QFileSystemModel只显示名称,不显示size,type,modified
    非Qt工程使用Qt的信号槽机制
    web性能权威指南(High Performance Browser Networking)
    缓存穿透 缓存并发 缓存失效
    互联网架构-基础中间件
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/7228709.html
Copyright © 2011-2022 走看看