【发布时间】:2011-11-01 17:35:37
【问题描述】:
我在一个 viewController 上创建了一个按钮,它使用 UIModalPresentationFormSheet 演示样式以模态方式加载另一个视图。在这个加载的视图中,我有两个 textField,我强制第一个 textField 成为第一响应者,以便键盘将立即出现在新视图中。我已将 textFields 设置为具有与“退出时结束”事件挂钩的操作方法。但是,每当我在键盘上为任一文本字段点击“返回”时,键盘都无法消失(这是我的代码):
// addCustomPage method that is called when button from original view is touched
- (IBAction) addCustomPage:(id)sender
{
NSLog(@"Adding Custom Page");
if (!self.customPageViewController)
{
self.customPageViewController =
[[CustomPageViewController alloc] initWithNibName:@"CustomPageViewController" bundle: nil];
}
customPageViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:customPageViewController animated:YES];
// force keyboard to appear with loaded page on the first textField
[customPageViewController.firstTextField becomeFirstResponder];
}
@interface CustomPageViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *firstTextField;
@property (strong, nonatomic) IBOutlet UITextField *secondTextField;
- (IBAction)keyboardEndOnExit:(id)sender; // DID END ON EXIT EVENT
@end
//in CustomPageViewController.m
-(IBAction)keyboardEndOnExit:(id)sender
{
[sender resignFirstResponder];
}
这是一个相当直截了当的问题,我通常可以通过基本视图和文本字段使用这种技术来关闭键盘。我不确定是否使用这种演示格式的视图或设置会使事情变得不同。谢谢!
【问题讨论】:
-
如果您使用不同的模态演示样式,键盘是否会正确关闭?
标签: objective-c interface-builder ios5 xcode4.2 resignfirstresponder