“已使用用户名”双击

时间:2014-04-25 12:09:31

标签: ios uialertview

在我的应用中使用注册流程时,提醒视图会在我快速双击注册按钮时显示“用户名已被采用”即使没有采取。有没有办法确保它在发生这种情况时显示警报视图或任何其他解决方案?

请参阅下面的代码:

NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *email = [self.emailField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

if ([username length] == 0 || [password length]  == 0 || [email length] == 0) {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!"
                                                        message:@"Make sure you enter a username, password, and email address with at least 5 characters!"
                                                       delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];                
    [alertView show];
}
else {
    PFUser *newUser = [PFUser user];
    newUser.username = username;
    newUser.password = password;
    newUser.email = email;

    [newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!"
                                                                message:[error.userInfo objectForKey:@"error"]
                                                               delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
        else 
        {

            [self saveUserDefaults];                
            [self dismissViewControllerAnimated:YES completion:nil];                
            [self performSegueWithIdentifier:@"setupProfile" sender:self];
        }

    }];

}

}

1 个答案:

答案 0 :(得分:1)

设置

  

setUserInteractionEnabled:否

点击第一个按钮上的按钮。

在你设置之前不允许任何点击

  

setUserInteractionEnabled:YES