[英]UITextField cannot get keyboard when mulple alertView popup?
In order to satisfy the need of my leader, I have to pop up multiple alertView
s (of style UIAlertViewStyleSecureTextInput
when a signal come). 为了满足我的领导者的需要,我必须弹出多个
alertView
(信号到来时为UIAlertViewStyleSecureTextInput
样式)。
But I am encountering a strange error... After multiple alertView
popups, I lose the focus of another textField
. 但是我遇到一个奇怪的错误...在弹出多个
alertView
之后,我失去了另一个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: 我尝试了三种方法来避免此类问题:
didDisplayAlarm
to reduce the popup of alertView
didDisplayAlarm
以减少didDisplayAlarm
的弹出alertView
alertView
alertView
dismiss方法 resignFirstResponder
in the alertView delegate
alertView delegate
使用textfield resignFirstResponder
My environment is IOS 6.1.3 but all doesn't work,so please help me 我的环境是IOS 6.1.3,但所有功能均无法正常使用,请帮助我
The problem here is you are using resignFirstResponder
but your textfield is not identifying which one to resign. 这里的问题是您使用的是
resignFirstResponder
但是您的文本字段无法标识要辞职的人。 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.
例如,如果您有多个alertView且每个都包含单独的文本字段,请说。 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.
因此,要确定文本字段,只需在文本字段上设置标签值,然后在标签值的基础上将文本字段辞职,并使另一个文本字段成为第一响应者。
when you click ok/cancel in alertview you need to resign your keyboard. 当您在Alertview中单击“确定” /“取消”时,您需要退出键盘。
to get UITextField from alertview in clickedButtonAtIndex: delegate method we have two options 要从clickedButtonAtIndex中的alertview中获取UITextField:委托方法,我们有两个选择
option 1 - loop the subviews of alert and get the instance of textfiled and resign it. 选项1-循环Alert的子视图,并获取textfiled的实例,然后将其签名。
for (UIView* view in alertView.subviews)
{
if ([view isKindOfClass:[UITextField class]])
{
UITextField* textField = (UITextField*)view;
NSLog(@"text:[%@]", textField.text);
break;
}
}
option 2 - you can get the textfiled instance by [alertView textFieldAtIndex:0].text
. 选项2-您可以通过
[alertView textFieldAtIndex:0].text
获取textfiled实例。 I think this can be done only if the alert style is UIAlertViewStylePlainTextInput
. 我认为只有在警报样式为
UIAlertViewStylePlainTextInput
才能完成此操作。
I hope this is helpful to you. 希望对您有帮助。 Thanks.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.