0

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.

4

1 回答 1

0

你想要这样的东西:

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

顺便说一句 - 修复你的大写锁定键。方法和变量名称应使用 camelCase(以小写字母开头)。类名应使用 CamelCase(以大写字母开头)。

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

在这种情况下,不需要所有额外的变量。

于 2013-10-18T01:30:17.283 回答