zoukankan      html  css  js  c++  java
  • 计算器 UITextField

    • 判断UITextField的输入的内容不能为空:(注意:判断UITextField有没有输入字符用字符的length来判断)
      - (IBAction)calculate {
          // 1.拿到用户输入的第一个数字
          NSString *num1String = self.num1Field.text;
          if (num1String.length == 0) {
              
              /*
              UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"输入有误" message:@"第一个输入框不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
              [alertView show];
               */
              [self showError:@"第一个输入框不能为空"];
              
              return;
          }
          
          // 2.拿到用户输入的第二个数字
          NSString *num2String = self.num2Field.text;
          if (num2String.length == 0) {
              
              /*
              UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"输入有误" message:@"第二个输入框不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
              [alertView show];
               */
              [self showError:@"第二个输入框不能为空"];
              
              return;
          }

      3.展示信息的错误方法

    • 1 // 展示错误信息
      2 - (void)showError:(NSString *)error
      3 {
      4     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"输入有误" message:error delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
      5     [alertView show];
      6 }
  • 相关阅读:
    epoll oneshot
    回望五月
    都知道的copy_from_user
    ixgbe 驱动 为xxx驱动做准备1
    面试问题集锦
    数据治理
    阅读
    hive 数据仓库面试题目集锦
    面试小问题集锦
    Scala学习笔记~尚硅谷学习视频
  • 原文地址:https://www.cnblogs.com/mshong1616/p/5095407.html
Copyright © 2011-2022 走看看