zoukankan      html  css  js  c++  java
  • iOS警示框—判断是否有空格和回车

    //输入框是否为空(判断空格和回车)
    -(BOOL)isEmpty:(NSString *)string
    {
        if (!string) {
            return YES;
        }else
        {
            NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
            NSString *str = [string stringByTrimmingCharactersInSet:set];
            if (str.length == 0) {
                return YES;
            }else{
                return NO;
            }
        }
    }
    
    //警示框
    -(void)alert{
        
        NSString *message = nil;
        if([self isEmpty:self.userTextField.text]){    //调用函数把空格处理为0
            message = @"请输入用户名";
        }else if(self.pwdTextField.text.length == 0){    //密码可以带空格
            message = @"请输入密码";
        }
        if(message)
        {
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
            UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            //    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:nil];
            [alertController addAction:action1];
            [alertController addAction:action2];
            //    [alertController addAction:action3];
            [self presentViewController:alertController animated:YES completion:nil];
        }
    }
    

      

  • 相关阅读:
    用nginx解决前端跨域问题
    vue中router-link的详细用法
    leetcode 148 排序链表
    leetcode 146 LRU缓存机制
    leetcode 101 对称二叉树
    leetcode 84 柱状图中最大的矩形
    leetcode76 最小覆盖子串
    C++ map, unordered_map
    python随机函数
    丑数
  • 原文地址:https://www.cnblogs.com/ios988/p/5289703.html
Copyright © 2011-2022 走看看