0

我目前正在编写一个应用程序,该应用程序具有以 Parse 作为后端的登录和注册页面。我能够获得用户名和所有注册的用户名,但是如果其中一个字段为空白,我需要有关通知用户的代码的帮助。我想显示错误的 UIAlertView 并防止在这种情况下切换视图(它切换然后显示字段留空的通知)。我知道这可能很简单。只需要一点帮助。这是下面的代码。

-(IBAction)signUpUserPressed:(id)sender
{

PFUser *user = [PFUser user];
user.username = self.userRegisterTextField.text;
user.password = self.passwordRegisterTextField.text;



[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        [self performSegueWithIdentifier:@"FinishSignup" sender:self];
    } else {



        [[[UIAlertView alloc] initWithTitle:@"Error" message:[error userInfo][@"error"] delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil] show];
    }
}];
}

帮助将不胜感激。这也类似于您正在注销应用程序并询问您是否要注销 - 停止视图切换和显示通知。

谢谢!

4

1 回答 1

0

在调用 signUpInBackgroundWithBlock 之前:自己检查字段是否为空。

PFUser *user = [PFUser user];
user.username =     self.userRegisterTextField.text;
user.password =   self.passwordRegisterTextField.text;

if (user.username.length > 0 && user.password.length > 0) {
    //sign up only if username/password given
    [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        [self  performSegueWithIdentifier:@"FinishSignup" sender:self];
   } else {



        [[[UIAlertView alloc] initWithTitle:@"Error" message:[error userInfo][@"error"] delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil] show];
    }
}];
}
}
else {
//show alert that username or password was left blank
}
于 2013-08-19T21:50:05.463 回答