简体   繁体   English

UIAlertview后数字键盘跳

[英]Number keypad jumping after UIAlertview

I have a login screen that shows an alert when the user gets the password wrong on a number of occasions. 我有一个登录屏幕,当用户多次输入错误密码时会显示警报。 On clicking one of the buttons, another alert view is presented to confirm, if I press the cancel button on this second alert view, the number keypad bounces from the bottom of the screen back up to its original position. 单击其中一个按钮时,将显示另一个警报视图以确认,如果我在第二个警报视图上按“取消”按钮,则数字小键盘会从屏幕底部弹回到原来的位置。 No code is being executed during this second alert response. 在第二个警报响应期间,没有代码正在执行。 Can someone help? 有人可以帮忙吗?

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

This is how i will do it. 这就是我要做的。

in the header file: 在头文件中:

UIAlertView *loginError;

in the implementation file: 在实现文件中:

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

Hope this helps... 希望这可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM