2013-03-07 37 views
0

我有一个登录屏幕,用户在多次获取密码错误时会显示警报。点击其中一个按钮时,会出现另一个警报视图以确认,如果我在第二个警报视图上按取消按钮,数字键盘将从屏幕底部弹回到其原始位置。在第二次警报响应期间没有代码正在执行。有人可以帮忙吗?UIAlertview后跳跃的数字键盘

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

回答

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

希望这有助于...

+0

谢谢你,作品一种享受! – Carl 2013-03-07 18:18:50