简体   繁体   English

在iOS中隐藏键盘

[英]Hide Keyboard in iOS

I want to hide the keyboard after entering the data. 我想在输入数据后隐藏键盘。

I have tried both methods which are given below. 我尝试了下面给出的两种方法。

[self.textField resignFirstResponser];
[self.view endEditing:YES];

Both are working well but i want to know the difference between these two lines. 两者都运作良好,但我想知道这两行之间的区别。

Thanks 谢谢

[self.view endEdtiting:YES]; 

From Docs: 来自Docs:

"Causes the view (or one of its embedded text fields) to resign the first responder status." “导致视图(或其中一个嵌入的文本字段)重新签署第一个响应者状态。”

"force: Specify YES to force the first responder to resign, regardless of whether it wants to do so. ReturnValue: YES if the view resigned the first responder status or NO if it did not." “force:指定YES以强制第一个响应者辞职,无论是否要这样做.ReturnValue:如果视图重新响应第一个响应者状态则为YES,否则为NO。”

[self.textField resignFirstReponder];

"Notifies the receiver that it has been asked to relinquish its status as first responder in its window" “通知接收方已被要求放弃其作为第一响应者在其窗口中的状态”

In general, both the methods are used to hide the keyboard or lose the focus on a TextField. 通常,这两种方法都用于隐藏键盘或将焦点丢失在TextField上。 The [self.view EndEditing:YES] tells the program to end any editing process that are taking place in a view (or its subview). [self.view EndEditing:YES]告诉程序结束视图(或其子视图)中发生的任何编辑过程。 Hence, it apparently hides the keyboard that was up for editing. 因此,它显然隐藏了用于编辑的键盘。 This happens regardless of any specific textfield. 无论任何特定的文本字段都会发生这种情 Whereas, [self.textField resignFirstResponder] method resigns its response towards editing the specified textField in the method (self.textField). 然而, [self.textField resignFirstResponder]方法将其响应重新设置为编辑方法中的指定textField(self.textField)。 Thus loses focus and hides the keyboard. 因此失去焦点并隐藏键盘。

Sending the -endEditing:(BOOL) force call to the view containing the input first responder will cause the text field to be sent a resign message, causing the on-screen keyboard to be dismissed. 发送-endEditing:(BOOL)强制调用包含输入第一响应者的视图将导致文本字段被发送一个resign消息,导致屏幕键盘被解除。

resignFirstResponder removes the present first responder in the UIResponder hierarchy resignFirstResponder删除UIResponder层次结构中的当前第一响应者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM