In order to satisfy the need of my leader, I have to pop up multiple alertViews (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
didDisplayAlarmto reduce the popup ofalertView - use dismiss method of
alertView - use textfield
resignFirstResponderin thealertView delegate
My environment is IOS 6.1.3 but all doesn't work.
The problem here is you are using
resignFirstResponderbut your textfield is not identifying which one to resign. So when you are resigning the textfield then you have to make other textfield to be first responder. For example,lets say if you have multiple alertView and each contains separate textfield. So for determining the textfield just set the tag Value on textfield and on the basis of tag value resign the textfield and make other one textfield to be the first responder.