iphone - 关闭 UIAlertView 中 UITextField 的键盘

标签 iphone iphone-softkeyboard

我有一个自定义的 UIAlertView。我在该 AlertView 中有一个 UITextField,它一显示就成为第一个响应者。现在,当用户触摸 AlertView 中的其他位置时,我需要关闭该 UITextField 的键盘。我为此设置了 TouchBegan 事件。

一切都已就位并且工作正常,除了当我在 UITextField 上调用 resignFirstResponder 时,它不再是第一响应者,但键盘并没有被关闭。有什么方法可以关闭该键盘。

我正在寻找解决方案,发现了类似的帖子 here没有答案

如果有人能找到出路,请告诉我。我什至尝试了以下方法,但它不起作用

UIWindow* tempWindow;

    // Because we cant get access to the UIKeyboard throught the SDK we will just use UIView. 
    // UIKeyboard is a subclass of UIView anyways
    UIView* keyboard;

    // Check each window in our application
    for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
    {
        // Get a reference of the current window
        tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
        for(int i = 0; i < [tempWindow.subviews count]; i++)
        {
            // Get a reference to the current view
            keyboard = [tempWindow.subviews objectAtIndex:i];

            // Loop through all views in the current window

            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES){
                [keyboard removeFromSuperview];
            }

        }
    }

最佳答案

您必须在 UIAlertField 上调用 resignFirstResponder,

例如:

[textField resignFirstResponder];[alertView resignFirstResponder];

关于iphone - 关闭 UIAlertView 中 UITextField 的键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4006790/

相关文章:

ios - 返回导航后不需要的键盘

iphone - 在编辑时禁用 UITextField 上的键盘

iphone - iPhone 中的高级搜索实现?

iphone - OpenGL ES代码修改

iphone - 为 UItextview 键盘设置动画

iphone - iPhone上触摸空白区域时如何隐藏键盘

iphone - 改变iphone键盘的颜色

iphone - 如果我使用 .xib 文件,如何提供 iPad 和 iPhone 5 版本?

iphone - 如何在 sqlite 中创建时间戳字段,以便正确初始化具有 NSDate 字段的核心数据对象?

iphone - iOS: subview 的 xcode 实例