
作为旁注,我是否必须关闭“每个”和“每个”字段的键盘,还是可以全局完成?哦,如果我不必触摸DONE按钮,那将是非常酷的,我理想地喜欢一个解决方案,用户触摸任何东西,但有问题的字段和键盘自动消失…
哦,如果你是如此善良的一步一步的指示.
我应该补充一点,我已经有一种方法可以让键盘辞职….
但是,它仅在我的表单提交时运行! (见下面的方法)
我的问题是如何键盘隐藏/解散而不必跳过这么多该死的箍! 6年后你会想到一个成熟的 *** 作系统会有一种全局隐藏键盘的方法….不!
好吧,够抱怨……
- (voID)hIDeKeyboard {[self.dancePlace resignFirstResponder];[self.danceGate resignFirstResponder];[self.danceTerminal resignFirstResponder];[self.danceText resignFirstResponder];[self.danceDate resignFirstResponder];[self.danceStyle resignFirstResponder];[self.danceTimeOut resignFirstResponder];} 这是在提交我的按钮时调用的….
- (IBAction)addListingpressed:(ID)sender {// NSLog(@"button pressed");[self hIDeKeyboard];[self valuesAdded];} 我的问题,假设任何人都可以回答这个……我怀疑没有,如果以下条件是MET,有没有办法全局隐藏键盘:1.)用户点击任何一个现有字段的OUT,2.)按下屏幕上的任何其他位置. 3.)现有的vIEwcontroller.m文件中只有一行或两行. 4.)我不必在vIEwcontroller上添加一个令人困惑的按钮. (任何时候我必须添加插座,这个该死的东西都会撞到我身上……然后发生了肮脏的事情,而且真的……记得我只是一个初学者,而且读起来很困惑我必须把它放在这里那里…… oy.简单的人,简单.我不是在寻找优雅的解决方案,只是为了它的工作原理.
解决方法 我有一个超级类,我的所有视图控制器都继承自.在那堂课里,我有这段代码.MySuperVIEwController.h
#import <UIKit/UIKit.h>@interface MySuperVIEwController : UIVIEwController@property(strong,nonatomic) UITapGestureRecognizer *backgroundTapGestureRecognizer;@end
MySuperVIEwController.m
- (voID)vIEwDIDLoad{ //add a tap gesture recognizer to capture all tap events //this will include tap events when a user clicks off of a textfIEld self.backgroundTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onBackgroundTap:)]; self.backgroundTapGestureRecognizer.numberOfTapsrequired = 1; self.backgroundTapGestureRecognizer.cancelstouchesInVIEw = NO; [self.vIEw addGestureRecognizer:self.backgroundTapGestureRecognizer];}- (voID)onBackgroundTap:(ID)sender{ //when the tap gesture recognizer gets an event,it calls endEditing on the vIEw controller's vIEw //this should dismiss the keyboard [[self vIEw] endEditing:YES];} 我将UITapGestureRecognizer作为公共属性,因此如果需要,我可以覆盖它.
子类
MyVIEwController.h
#import <UIKit/UIKit.h>#import "MySuperVIEwController.h" @interface MyVIEwController : MySuperVIEwController<UIGestureRecognizerDelegate>@end
MyVIEwController.m
- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; // Do any additional setup after loading the vIEw. //You don't always want the keyboard to be dismissed,so you tIE into the gesture recognizer's delegate method //By doing this,you can stop the endEditing call from being made [self.backgroundTapGestureRecognizer setDelegate:self];}- (BOol)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceive@R_404_5985@:(UI@R_404_5985@ *)@R_404_5985@{ //@R_404_5985@.vIEw is the vIEw that recIEved the @R_404_5985@ //if this vIEw is another textfIEld or maybe a button,you can return NO and the endEditing call won't be made if (@R_404_5985@.vIEw == self.myVIEwThatShouldNotBeBlocked) { return NO; } //if you want the gesture recognizer to accept the event,return yest return YES;} 我上传了一个示例项目到github.
https://github.com/JeffRegan/KeyboardBeGone
以上是内存溢出为你收集整理的ios – 使用MULTIPLE UITextFields关闭键盘?全部内容,希望文章能够帮你解决ios – 使用MULTIPLE UITextFields关闭键盘?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)