【发布时间】:2011-06-08 18:37:35
【问题描述】:
我遇到了与 Anthony Chan's question 类似的问题,在尝试了所有建议的解决方案后,我仍然卡住了。
不知何故,只有在与我的 UIAlertView 交互后,我才能在我的应用程序的另一个视图中关闭键盘。就好像警报正在破坏我的 UITextField 的 resignFirstResponder 能力。下面我实例化我的 UIAlertView,然后调用它的 didDismissWIthButtonIndex 方法。然后,我调用 showInfo 方法,该方法加载另一个 UIViewController。
UIAlertView *emailFailAlert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"error message text."
delegate:self
cancelButtonTitle:@"Not now"
otherButtonTitles:@"Settings", nil];
[emailFailAlert setTag:2];
[emailFailAlert show];
[emailFailAlert release];
按下“设置”选项后,我将调用此方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if ([alertView tag] == 2) {
if (buttonIndex == 1){
[self showInfo:nil];
}
}
}
我的 showInfo 方法通过以下代码加载另一个 ViewController:
- (IBAction)showInfo:(id)sender {
FlipsideViewController *fscontroller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
fscontroller.delegate = self;
fscontroller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:fscontroller animated:YES];
[fscontroller release];
}
单击此 Flipside VC 中的任何文本字段后,我无法像平常使用 - (BOOL)textFieldShouldReturn:(UITextField *)textField 和 [textField resignFirstResponder] 那样关闭键盘。我已经省略了这段代码,因为这个问题很长,但如果有必要我很乐意发布。
有趣的是,如果我在单击按钮时注释掉 [self showInfo:nil] 调用并通过单击测试按钮(在 alertView didDismissWithButtonIndex: 方法之外)调用它,一切正常。知道这里发生了什么吗?
提前致谢!
【问题讨论】:
-
更新:将 [self showInfo:nil] 更改为 [self performSelector:@selector(showInfo:) withObject:nil afterDelay:.1] 有效,但似乎这可能会在较慢的设备上中断(或在模拟器之外)......感觉就像一个奇怪的范围问题。任何帮助表示赞赏!
-
遇到了您描述的相同问题。出于某种原因,如果您安排模态演示(或在我的情况下关闭)在下一个运行循环中运行,那么问题就会消失 - 键盘不会作为第一响应者卡住。谢谢!
-
我还要注意 - 这个问题似乎只影响 iOS4。我在 iOS5+ 中没有看到这个问题。
标签: iphone ios keyboard uitextfield uialertview