Question

i'm trying to make my first user-registration. The registration will be made by 4 textfields that need to be edited by the user and saved after pushing a button (IBAction). This IBAction needs to be aborted when 1 field is empty. A warning text will be shown to the user and he/she will need to correct the problem before proceeding to save the textdata to a parse server/

I've connected my 4 Uitextfields to the .m script AND i think i've written a good if statement. But how can I stop my script after the warning text?

CODE .M :

- (IBAction)REGISTERNEWUSER:(id)sender
{

    //DEFINE STRINGS FOR MODULE
    NSString *NICKNAME = Nickname.text;
    NSString *USERNAME = Username.text;
    NSString *PASSWORD = Password.text;
    NSString *EMAIL = Email.text;
    NSString *ERRORREGISTRATION = @"Please fill up all fields above before proceeding with the  registration...";

    //CHECK IF ALL REGISTRATION FIELDS ARE FILLED
    if ([Nickname.text length] > 0 || [Username.text length] > 0 || [Password.text length] > 0 || [Email.text length] > 0 )
    {
    }
    ErrorRegistration.text = ERRORREGISTRATION;

    //
    // METHODE NEEDS TO STOP HERE
    // BUT AT MOMENT CONTINUES TO SEND DATA TO PARSE
    //
    {

    }


    //SEND DATA TO PARSE SERVER
    PFObject *User = [PFObject objectWithClassName:@"USER"];
    [User setValue:NICKNAME forKey:@"Nickname"];
    [User setValue:USERNAME forKey:@"Username"];
    [User setValue:PASSWORD forKey:@"Password"];
    [User setValue:EMAIL forKey:@"Email"];
    [User save];
}

Thanks in advance for any help provided. Kind Regards, Lien.

Was it helpful?

Solution

You want something like this:

if ([Nickname.text length] == 0 || [Username.text length] == 0 || [Password.text length] == 0 || [Email.text length] == 0 ) {
    // Not all fields are entered
    ErrorRegistration.text = ERRORREGISTRATION;
} else {
    // All fields are entered
    //SEND DATA TO PARSE SERVER
    PFObject *User = [PFObject objectWithClassName:@"USER"];
    [User setValue:NICKNAME forKey:@"Nickname"];
    [User setValue:USERNAME forKey:@"Username"];
    [User setValue:PASSWORD forKey:@"Password"];
    [User setValue:EMAIL forKey:@"Email"];
    [User save];
}

BTW - Fix your caps lock key. Method and variable names should use camelCase (beginning with a lowercase letter). Class names should use CamelCase (begging with an uppercase letter).

if ([nickname.text length] == 0 || [username.text length] == 0 || [password.text length] == 0 || [email.text length] == 0 ) {
    // Not all fields are entered
    errorRegistration.text = @"Please fill up all fields above before proceeding with the  registration...";
} else {
    // All fields are entered
    //SEND DATA TO PARSE SERVER
    PFObject *user = [PFObject objectWithClassName:@"USER"];
    [user setValue:nickname.text forKey:@"Nickname"];
    [user setValue:username.text forKey:@"Username"];
    [user setValue:password.text forKey:@"Password"];
    [user setValue:email.text forKey:@"Email"];
    [user save];
}

No need for all of the extra variables in this case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top