【问题标题】:TextField will NOT resign first responder with UIModalPresentationFormSheet viewTextField 不会使用 UIModalPresentationFormSheet 视图辞去第一响应者的职务
【发布时间】: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


【解决方案1】:

您已确认您的keyboardEndOnExit 方法实际上正在被调用?

您还可以通过调用 [yourTextView resignFirstResponder] 来采取更直接的方法,当用户采取特定操作时,例如按下键等。我仍然会检查是否曾经使用断点或日志调用该方法.

【讨论】:

    【解决方案2】:

    看看this question。很确定这是由 UIModalPresentationFormSheet 引起的相同问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      相关资源
      最近更新 更多