In order to satisfy the need of my leader, I have to pop up multiple alertView
s (of style UIAlertViewStyleSecureTextInput
when a signal come).
But I am encountering a strange error... After multiple alertView
popups, I lose the focus of another textField
.
the following code:
if (!didDisplayAlarm && (timeInterval < -_alertStopTime) && (self.isMainViewController)) {
didDisplayAlarm = YES; //first method
if (_alertView) {
[_alertView dismissWithClickedButtonIndex:0 animated:NO]; //second method
}
_alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:@"ignore"
otherButtonTitles:@"check", nil];
_alertView.tag = kAlarmTag;
alarmUser = [NSString stringWithFormat:@"%d", [[dict objectForKey:@"alarmUser"] intValue]];
alarmPassword = nil;
_alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
UITextField *alertTextField = [_alertView textFieldAtIndex:0];
alertTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
alertTextField.keyboardType = UIKeyboardTypeNumberPad;
[alertTextField setPlaceholder:@"please input password"];
[_alertView show];
}
I tried three method to avoid such issue:
- set a bool var
didDisplayAlarm
to reduce the popup ofalertView
- use dismiss method of
alertView
- use textfield
resignFirstResponder
in thealertView delegate
My environment is IOS 6.1.3 but all doesn't work.
When you click ok/cancel in alertview you need to resign your keyboard.
to get UITextField from alertview in clickedButtonAtIndex: delegate method we have two options
Option 1 - loop the subviews of alert and get the instance of textfiled and resign it.
Option 2 - you can get the textfiled instance by
[alertView textFieldAtIndex:0].text
. I think this can be done only if the alert style isUIAlertViewStylePlainTextInput
.