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 }
  • 相关阅读:
    内存条的物理结构分析【转载】
    JDK动态代理[2]----动态代理设计模式(文章转载于别处)
    shell 计算
    如何使用Vagrant创建linux环境(MacOS版)
    JavaFreemarker01快速上手
    7、验证信息
    6、更新文档
    5、删除文档
    4、查询文档02
    3、查询文档01
  • 原文地址:https://www.cnblogs.com/mshong1616/p/5095407.html
Copyright © 2011-2022 走看看