iPhone 键盘、完成按钮和 resignFirstResponder

iPhone keyboard, Done button and resignFirstResponder(iPhone 键盘、完成按钮和 resignFirstResponder)
本文介绍了iPhone 键盘、完成按钮和 resignFirstResponder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我在文档中找不到答案.弹出式键盘上的完成"按钮是否总是导致键盘消失?我在网上看到很多这样的代码:

This is probably a dumb question, but I can't find the answer in the docs. Did the "Done" button on the pop-up keyboard always cause the keyboard to disappear? I see a lot of code around the web like this:

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    [theTextField resignFirstResponder];
    return YES;
}

当我按下完成"按钮时,键盘弹出,UITextField 退出第一响应者.

When I press the "Done" button, the keyboard pops down and the UITextField resigns first responder.

我假设按下完成"按钮不会导致 UITextField 变为 resignFirstResponder,但这种行为有时会发生变化.

I'm presuming that pressing the "Done" button didn't used to cause a UITextField to resignFirstResponder, but that behavior changed at some time.

我在 OS 3.0 - 3.1.3 上调试

I'm debugging on OS 3.0 - 3.1.3

推荐答案

我做了一个小测试项目,只有一个 UITextField 和这段代码

I made a small test project with just a UITextField and this code

#import <UIKit/UIKit.h>
@interface TextFieldTestViewController : UIViewController
<UITextFieldDelegate>
{
    UITextField *textField;
}
@property (nonatomic, retain) IBOutlet UITextField *textField;
@end

#import "TextFieldTestViewController.h"
@implementation TextFieldTestViewController
@synthesize textField;

- (void)viewDidLoad
{
    [self.textField setDelegate:self];
    [self.textField setReturnKeyType:UIReturnKeyDone];
    [self.textField addTarget:self
                  action:@selector(textFieldFinished:)
        forControlEvents:UIControlEventEditingDidEndOnExit];
    [super viewDidLoad];
}
- (IBAction)textFieldFinished:(id)sender
{
    // [sender resignFirstResponder];
}

- (void)dealloc {
    [super dealloc];
}
@end

文本字段是一个未修改的 UITextField,拖到 NIB 上,插座已连接.
加载应用程序后,单击文本字段会弹出键盘.按下完成"按钮会使文本字段失去焦点并动画键盘.请注意,网络上的建议是始终使用 [sender resignFirstResponder] 但没有它也可以.

The text field is an unmodified UITextField dragged onto the NIB, with the outlet connected.
After loading the app, clicking in the text field brings up the keyboard. Pressing the "Done" button makes the text field lose focus and animates out the keyboard. Note that the advice around the web is to always use [sender resignFirstResponder] but this works without it.

这篇关于iPhone 键盘、完成按钮和 resignFirstResponder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)