溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

iOS UITextField或UITextView的內(nèi)容是否為空

發(fā)布時(shí)間:2020-07-06 00:10:06 來(lái)源:網(wǎng)絡(luò) 閱讀:1369 作者:卓行天下 欄目:移動(dòng)開(kāi)發(fā)


//判斷正在編輯的UITextField或UITextView的內(nèi)容是否為空,判斷正在編輯的UITextField或UITextView的內(nèi)容是否為空,以此來(lái)控制button的點(diǎn)亮狀態(tài)

#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 = [UIColor redColor].CGColor;

       tfPostName.layer.borderWidth =1.0;

        tfPostName.layer.cornerRadius =5.0;

        

        return NO;

    }

    else if (tfPositionType.text.length<1){

        //02

        tfPositionType.layer.borderColor = [UIColor redColor].CGColor;

        tfPositionType.layer.borderWidth =1.0;

        tfPositionType.layer.cornerRadius =5.0;

        

        return NO;

    }

    

    else if ( tfPeopleNum.text.length<1){

        //03

         tfPeopleNum.layer.borderColor = [UIColor redColor].CGColor;

         tfPeopleNum.layer.borderWidth =1.0;

         tfPeopleNum.layer.cornerRadius =5.0;

        return NO;

    }

    

    else if ( tfWages.text.length<1){

        //04

         tfWages.layer.borderColor = [UIColor redColor].CGColor;

         tfWages.layer.borderWidth =1.0;

         tfWages.layer.cornerRadius =5.0;

        return NO;

        

    }else if (tfUnit.text.length<1){

        //05

        tfUnit.layer.borderColor = [UIColor redColor].CGColor;

        tfUnit.layer.borderWidth =1.0;

        tfUnit.layer.cornerRadius =5.0;

        return NO;

        

    }else if (tfStartDate.text.length<1){

        //07

        tfStartDate.layer.borderColor = [UIColor redColor].CGColor;

        tfStartDate.layer.borderWidth =1.0;

        tfStartDate.layer.cornerRadius =5.0;

        return NO;

        

    }else if (tfEndDate.text.length<1){

        //08

        tfEndDate.layer.borderColor = [UIColor redColor].CGColor;

        tfEndDate.layer.borderWidth =1.0;

        tfEndDate.layer.cornerRadius =5.0;

        return NO;

        

    }else if (tfSescribe.text.length<1){

        //09

        tfSescribe.layer.borderColor = [UIColor redColor].CGColor;

        tfSescribe.layer.borderWidth =1.0;

        tfSescribe.layer.cornerRadius =5.0;

   

        //tfSescribe.text.length == 0;

        return NO;

    }


//    }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;

//        

//    }

        else if (tfContactPerson.text.length<1){

        //11

        tfContactPerson.layer.borderColor = [UIColor redColor].CGColor;

       tfContactPerson.layer.borderWidth =1.0;

       tfContactPerson.layer.cornerRadius =5.0;

        return NO;

    }

    else if ( tfContactPhone.text.length<1){

        //12--

       tfContactPhone.layer.borderColor = [UIColor redColor].CGColor;

       tfContactPhone.layer.borderWidth =1.0;

       tfContactPhone.layer.cornerRadius =5.0;

        return NO;

        

    }else if (tfJobArea.text.length<1){

        //13

        tfJobArea.layer.borderColor = [UIColor redColor].CGColor;

        tfJobArea.layer.borderWidth =1.0;

        tfJobArea.layer.cornerRadius =5.0;

        return NO;

    }

    else if (tfDetailAddress.text.length<1){

        //14--

        tfDetailAddress.layer.borderColor = [UIColor redColor].CGColor;

        tfDetailAddress.layer.borderWidth =1.0;

        tfDetailAddress.layer.cornerRadius =5.0;

        return NO;

        

    }else if (tfUnit.text.length<1){

        //15

        tfUnit.layer.borderColor = [UIColor redColor].CGColor;

        tfUnit.layer.borderWidth =1.0;

        tfUnit.layer.cornerRadius =5.0;

        return NO;

    }

    

    else {

        return YES;

    }

    

}



//崗位描述不能為空的判斷

#pragma mark- UITextViewDelegate

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

{

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

    [changedString replaceCharactersInRange:range withString:text];

    

    if (changedString.length<1) {

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

         [CMNavBarNotificationView notifyWithText:@"" andDetail:@"請(qǐng)完善發(fā)布信息"];

    }else{

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

        //[CMNavBarNotificationView notifyWithText:@"" andDetail:@"請(qǐng)完善發(fā)布信息"];

    }

    

    return YES;

}




向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI