iOSUITextField或UITextView的内容是否为空-成都快上网建站

iOSUITextField或UITextView的内容是否为空

//判断正在编辑的UITextField或UITextView的内容是否为空,判断正在编辑的UITextField或UITextView的内容是否为空,以此来控制button的点亮状态

成都创新互联公司自2013年起,先为吉林等服务建站,吉林等地企业,进行企业商务咨询服务。为吉林企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

#pragma mark- UITextFieldDelegate

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{

    

    NSMutableString * changedString=[[NSMutableString alloc]initWithString:textField.text];

    [changedString replaceCharactersInRange:range withString:string];

    

    if (changedString.length!=0) {

        self.navigationItem.rightBarButtonItem.enabled=YES;

    }else{

        self.navigationItem.rightBarButtonItem.enabled=NO;

    }

    return YES;

}

#pragma mark- UITextViewDelegate

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text

{

    NSMutableString * changedString=[[NSMutableString alloc]initWithString:textView.text];

    [changedString replaceCharactersInRange:range withString:text];

    

    if (changedString.length!=0) {

        self.navigationItem.rightBarButtonItem.enabled=YES;

    }else{

        self.navigationItem.rightBarButtonItem.enabled=NO;

    }

    

    return YES;

}

//一些判断技巧

- (BOOL)verifyData{

   if(tfPostName.text.length<1){

       //01

       tfPostName.layer.borderColor = [UIColorredColor].CGColor;

      tfPostName.layer.borderWidth =1.0;

       tfPostName.layer.cornerRadius =5.0;

        

       returnNO;

    }

   elseif (tfPositionType.text.length<1){

       //02

       tfPositionType.layer.borderColor = [UIColorredColor].CGColor;

       tfPositionType.layer.borderWidth =1.0;

       tfPositionType.layer.cornerRadius =5.0;

        

       returnNO;

    }

    

   elseif (tfPeopleNum.text.length<1){

       //03

        tfPeopleNum.layer.borderColor = [UIColorredColor].CGColor;

        tfPeopleNum.layer.borderWidth =1.0;

        tfPeopleNum.layer.cornerRadius =5.0;

       returnNO;

    }

    

   elseif (tfWages.text.length<1){

       //04

        tfWages.layer.borderColor = [UIColorredColor].CGColor;

        tfWages.layer.borderWidth =1.0;

        tfWages.layer.cornerRadius =5.0;

       returnNO;

        

    }elseif (tfUnit.text.length<1){

       //05

       tfUnit.layer.borderColor = [UIColorredColor].CGColor;

       tfUnit.layer.borderWidth =1.0;

       tfUnit.layer.cornerRadius =5.0;

       returnNO;

        

    }elseif (tfStartDate.text.length<1){

       //07

       tfStartDate.layer.borderColor = [UIColorredColor].CGColor;

       tfStartDate.layer.borderWidth =1.0;

       tfStartDate.layer.cornerRadius =5.0;

       returnNO;

        

    }elseif (tfEndDate.text.length<1){

       //08

       tfEndDate.layer.borderColor = [UIColorredColor].CGColor;

       tfEndDate.layer.borderWidth =1.0;

       tfEndDate.layer.cornerRadius =5.0;

       returnNO;

        

    }elseif (tfSescribe.text.length<1){

       //09

       tfSescribe.layer.borderColor = [UIColorredColor].CGColor;

       tfSescribe.layer.borderWidth =1.0;

       tfSescribe.layer.cornerRadius =5.0;

   

       //tfSescribe.text.length == 0;

       returnNO;

    }

//    }else if (tfPayWay.text.length<1){

    

    

   //tfSescribe

    

    

//        //10--

//       tfPayWay.layer.borderColor = [UIColor redColor].CGColor;

//       tfPayWay.layer.borderWidth =1.0;

//       tfPayWay.layer.cornerRadius =5.0;

//        return NO;

//        

//    }

       elseif (tfContactPerson.text.length<1){

       //11

       tfContactPerson.layer.borderColor = [UIColorredColor].CGColor;

      tfContactPerson.layer.borderWidth =1.0;

      tfContactPerson.layer.cornerRadius =5.0;

       returnNO;

    }

   elseif (tfContactPhone.text.length<1){

       //12--

      tfContactPhone.layer.borderColor = [UIColorredColor].CGColor;

      tfContactPhone.layer.borderWidth =1.0;

      tfContactPhone.layer.cornerRadius =5.0;

       returnNO;

        

    }elseif (tfJobArea.text.length<1){

       //13

       tfJobArea.layer.borderColor = [UIColorredColor].CGColor;

       tfJobArea.layer.borderWidth =1.0;

       tfJobArea.layer.cornerRadius =5.0;

       returnNO;

    }

   elseif (tfDetailAddress.text.length<1){

       //14--

       tfDetailAddress.layer.borderColor = [UIColorredColor].CGColor;

       tfDetailAddress.layer.borderWidth =1.0;

       tfDetailAddress.layer.cornerRadius =5.0;

       returnNO;

        

    }elseif (tfUnit.text.length<1){

       //15

       tfUnit.layer.borderColor = [UIColorredColor].CGColor;

       tfUnit.layer.borderWidth =1.0;

       tfUnit.layer.cornerRadius =5.0;

       returnNO;

    }

    

   else {

       returnYES;

    }

    

}

//岗位描述不能为空的判断

#pragma mark- UITextViewDelegate

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{

   NSMutableString * changedString=[[NSMutableStringalloc]initWithString:tfSescribe.text];

    [changedStringreplaceCharactersInRange:rangewithString:text];

    

   if (changedString.length<1) {

       //self.navigationItem.rightBarButtonItem.enabled=YES;

         [CMNavBarNotificationViewnotifyWithText:@""andDetail:@"请完善发布信息"];

    }else{

       //self.navigationItem.rightBarButtonItem.enabled=NO;

       //[CMNavBarNotificationView notifyWithText:@"" andDetail:@"请完善发布信息"];

    }

    

   returnYES;

}


当前文章:iOSUITextField或UITextView的内容是否为空
文章起源:http://kswjz.com/article/ispihj.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流