我有一个自定义的 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/