0

ユーザーが何度もパスワードを間違えたときにアラートを表示するログイン画面があります。ボタンの1つをクリックすると、別のアラートビューが表示され、この2番目のアラートビューでキャンセルボタンを押すと、数字キーパッドが画面の下部から元の位置に戻ります。この2番目のアラート応答の間、コードは実行されていません。誰かが助けることができますか?

if (loginCount < 5) {
  // Display alert to user
  UIAlertView *loginError = [[UIAlertView alloc] initWithTitle:@"Login Failure" message:@"You have entered an incorrect passcode.  Please try again." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
  [loginError show];

  } else {
    // Display alert to user, including option to reset the app as they have 5 or more login failures
    UIAlertView *loginError = [[UIAlertView alloc] initWithTitle: @"Login Failure" message: @"You have entered an incorrect passcode on 5 or more occasions.  Please try again or reset the app." delegate: self cancelButtonTitle: @"Try Again" otherButtonTitles: @"Reset App", nil]
    [loginError show];
}
// Clear password fields
[self clearPasswordFields];
[passcode1 becomeFirstResponder];
// Increment the login count
loginCount++;

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    // If the user has chosen to reset the app, alert with a confirmation first before resetting
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if ([title isEqualToString:@"Reset App"]) {
        // Create alert to give the user the choice to confirm reset
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Reset" message:@"Are you sure you wish to Reset?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        [alert show];
    } else if ([title isEqualToString:@"Yes"] && buttonIndex == 1) {
        [Utilities resetApp];
        [self dismissViewControllerAnimated:NO completion:nil];
    }
}
4

1 に答える 1

1

これが私がそれをする方法です。

ヘッダーファイル内:

UIAlertView *loginError;

実装ファイル内:

-(void)textFieldDidEndEditing:(UITextField *)textField
{
  if (loginCount < 5) {
  // Display alert to user
  loginError = [[UIAlertView alloc] initWithTitle:@"Login Failure" message:@"You have entered an incorrect passcode.  Please try again." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
  [loginError show];

  } else {
    // Display alert to user, including option to reset the app as they have 5 or more login failures
    loginError = [[UIAlertView alloc] initWithTitle: @"Login Failure" message: @"You have entered an incorrect passcode on 5 or more occasions.  Please try again or reset the app." delegate: self cancelButtonTitle: @"Try Again" otherButtonTitles: @"Reset App", nil]
    [loginError show];
}
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    // If the user has chosen to reset the app, alert with a confirmation first before resetting
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if ([title isEqualToString:@"Reset App"]) {
        [self showSecondAlert];
    } else if ([title isEqualToString:@"Yes"] && buttonIndex == 1) {
        [Utilities resetApp];
        [self dismissViewControllerAnimated:NO completion:nil];
    }else{
      [self clearPasswordFields];
      [passcode1 becomeFirstResponder];
    }
}

-(void)showSecondAlert
{
        //make sure you dismiss the old alertview first
         [loginError dismissWithClickedButtonIndex:0  animated:NO];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Reset" message:@"Are you sure you wish to Reset?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        [alert show];
}

お役に立てれば...

于 2013-03-07T18:06:20.400 に答える