热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用多个文本字段解除第一响应者/键盘-DismissingtheFirstResponder/KeyboardwithmultipleTextfields

Likeseriouslyaftergoingthroughthis经过这个Easywaytodismisskeyboard?轻松解除键盘的方法?

Like seriously after going through this...

经过这个......

Easy way to dismiss keyboard?

轻松解除键盘的方法?

... I have multiple TextFields and a few TextViews. Is there not a way to a have a batch or group Dismiss First Responder for all text fields? Will I need to make method for each field? Maybe I overlooked something in that link?

...我有多个TextFields和一些TextViews。是否有办法让所有文本字段都有批处理或组Dismiss First Responder?我需要为每个领域制作方法吗?也许我忽略了那个链接中的某些东西?

Maybe I can follow something like this:

也许我可以遵循这样的事情:

https://stackoverflow.com/questions/3282837/problem-with-multiple-textfields-to-make-the-keyboard-dissapear

Would the latter make sense? Thanks in advance.

后者会有意义吗?提前致谢。

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

I figured it out....

我想到了....

Controller.h

@interface Controller : UIViewController  {
    IBOutlet UITextField *clickedDone;
}
@property (nonatomic, retain) IBOutlet UITextField *clickedDone;

Controller.m

#import "Controller.h"
@implementation Controller
@synthesize clickedDone;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [clickedDone setDelegate:self];
}

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

4 个解决方案

#1


4  

clickedDone.returnKeyType = UIReturnKeyDone;  // in viewDidLoad

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

#2


30  

The view has an endEditing: method you can use. The docs say

视图有一个endEditing:您可以使用的方法。文档说

Causes the view (or one of its embedded text fields) to resign the first responder status.

导致视图(或其中一个嵌入的文本字段)重新签署第一个响应者状态。

In your view controller you can just call:

在视图控制器中,您只需调用:

[[self view] endEditing:YES];

#3


2  

Its very easy now. You can follow different approach depending on your use cases. In my case I had multiple textfields in UITableViewController. What I did is this :

现在非常容易。您可以根据您的使用情况采用不同的方法。在我的例子中,我在UITableViewController中有多个文本字段。我做的是这样的:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [self.view endEditing:YES];
}

#4


1  

Best answer is:

最佳答案是:

  1. Added UITextFieldDelegate protocol to your viewcontroller @interface ViewController : UIViewController
  2. 将UITextFieldDelegate协议添加到viewcontroller @interface ViewController:UIViewController

  3. In your xib, select the textField, in your Ulitlites section in the right side pane of XCode in the subsection of "Connections Inspector", link the textField's delegate with the .xib's "File's Owner".
  4. 在你的xib中,选择textField,在“Connections Inspector”子部分的XCode右侧窗格的Ulitlites部分中,将textField的委托链接到.xib的“文件所有者”。

  5. In your Viewcontroller implementation, include the follwing
  6. 在Viewcontroller实现中,包括以下内容


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

推荐阅读
author-avatar
海峡整形美容医院少校
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有