Mathi Arasan
Mathi Arasan

Reputation: 889

How to check text field empty or not with tags xcode

I am using text fields for signup it's have 7 text fields like Name, Email ID, Phone number etc.,

How do I check each and every text field not empty. I am set tags each text field start from 101 to 108

Is anyway to check that with for loop text field empty or not.

Upvotes: 1

Views: 456

Answers (2)

Fahim Parkar
Fahim Parkar

Reputation: 31647

How about this?

int isError = 0;
UITextField *mTextField;
for (int i=101;i<=108;i++) {
    mTextField = (UITextField*)[self.view viewWithTag:i];
    if ([mTextField length]==0) {
        isError = 1;
        break;
    }
}

if (isError==1) {
    // alert there is error
} else {
    // continue with logic here
}

Upvotes: 3

maanslund
maanslund

Reputation: 164

Either you could run through your textfields with a for-loop, and check the contents of each field. If a textfield is empty at any point, you could set a boolean to false, and check the boolean after the loop is done.

if the boolean is false, you tell the user they need to fill out everything, if the boolean is true, they can continue.

Or you could write an if-statement for each field, and again, if any statement returns false, you show a warning to the user etc.

Upvotes: 0

Related Questions