我有一个通常在其登录窗口中使用UIAlertView的应用程序:
self.customAlert = [[IFCustomAlertView alloc] initWithTitle:@"Save Password"
message:@"¿Do you want the app to remember your password?"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
问题是...由于每当出现alertView时我就将设备更新到iOS8,它会显示键盘,而无法将其关闭。在iOS7上不会发生这种情况。
轻按“发送”按钮后,我将放弃用户和密码的响应者:
-(IBAction)btnSendTapped:(id)sender{
[self.tfpass resignFirstResponder];
[self.tfuser resignFirstResponder];
}
我努力了:
[self.view endEditing:YES];
在某些alertViews中它确实起作用,但在另一些中则无效。我的AlertViews从来没有文本字段,所以我认为没有理由出现此键盘。
键盘上的简介按钮也不会隐藏它,因此有时OK和Cancel按钮会被键盘遮住,而我在屏幕上什么也做不了。
我认为这可能与UIAlertView的弃用有关,但我不知道。
我还实现了以下方法:
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return true;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
return YES;
}
任何帮助,将不胜感激。
最佳答案
我从this博客借用解决方案
对我来说,总是在调用alertView.show()时显示键盘。
我的解决方案使用didPresentALertView方法来确保在警报视图弹出窗口后调用此方法。然后,我们可以遍历所有UIWindows及其子视图。我通过描述名称检测到它(如果需要,可以使用更准确的方法),只需将其从 super 视图中删除即可。
func didPresentAlertView(alertView: UIAlertView) {
var tempWindow: UIWindow;
var keyboard: UIView;
for var c = 0; c < UIApplication.sharedApplication().windows.count; c++ {
tempWindow = UIApplication.sharedApplication().windows[c] as! UIWindow
for var i = 0; i < tempWindow.subviews.count; i++ {
keyboard = tempWindow.subviews[i] as! UIView
println(keyboard.description)
if keyboard.description.hasPrefix("<UIInputSetContainerView") {
keyboard.removeFromSuperview()
}
}
}
}
希望这个主题。
关于ios - UIAlertView显示键盘,无法将其关闭,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29809752/