简体   繁体   English

多个alertView弹出窗口时,UITextField无法获取键盘吗?

[英]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: 我尝试了三种方法来避免此类问题:

  1. set a bool var didDisplayAlarm to reduce the popup of alertView 设置一个布尔didDisplayAlarm以减少didDisplayAlarm的弹出alertView
  2. use dismiss method of alertView 使用alertView dismiss方法
  3. use textfield 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.

相关问题 滥用UITextField.inputView获得类似的键盘弹出行为 - Misuse of UITextField.inputView to get similar popup behavior of keyboard 使用UITextField Popup Alertview获取文本和Swift 3致命错误 - Getting text with UITextField Popup Alertview with Swift 3 fatal error 以编程方式将 UITextField() 添加到 UI,无法点击字段以获取键盘 - Adding UITextField() to UI programmatically, cannot tap on field to get keyboard 在UINavigationItem中时,UITextField无法放弃其键盘 - UITextField cannot resign its keyboard when inside UINavigationItem 在uitextfield中点击时,用户无法调出键盘 - User cannot bring up keyboard when tapping in uitextfield UITextField上的键盘关闭,但无法单击其他UITextField - Keyboard on UITextField dismisses but cannot click other UITextField 没有UITextField的情况下如何弹出键盘 - How can I popup keyboard without UITextField 使用addSubview动态添加UITextField的UITableViewCell-如何在键盘上按“返回”键时获取UITextField值 - UITableViewCell with dynamically added UITextField using addSubview - How to get UITextField values when 'return' hit on keyboard 从键盘通知获取UITextField - Get UITextField from Keyboard Notifications UITextField在键盘阻止时移动 - UITextField moving when keyboard will block it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM