码迷,mamicode.com
首页 > 其他好文 > 详细

计算器 UITextField

时间:2016-01-03 00:21:16      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

  • 判断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 }

     

计算器 UITextField

标签:

原文地址:http://www.cnblogs.com/mshong1616/p/5095407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!