失去焦点时隐藏 iPhone 键盘
使用我在网上读到的内容,人们说在应用程序的后台放置一个按钮,然后单击该按钮即可关闭键盘。然而,阅读其他一些人的文章,他们说辞去文本字段的第一响应者 - 这是否意味着文本字段已经控制了键盘并且在明确告知之前不会释放它?
我的 .h 有:
@interface SearchItems : UIViewController {
IBOutlet UIButton *btnKeyboard;
IBOutlet UITextField *txtWhat;
IBOutlet UITextField *txtWhere;
}
@property (nonatomic, retain) IBOutlet UIButton *btnKeyboard;
@property (nonatomic, retain) IBOutlet UITextField *txtWhat;
@property (nonatomic, retain) IBOutlet UITextField *txtWhere;
-(IBAction)closeKeyboard;
@end
.m (删减)
@synthesize btnKeyboard, txtWhat, txtWhere;
-(IBAction)closeKeyboard {
[txtWhere resignFirstResponder];
[txtWhat resignFirstResponder];
}
哪个不起作用,有什么想法吗?
谢谢
汤姆
Using what I've read online people say put a button in the background of the app then when clicked that button handles closing the keyboard. However reading some other people they say resign first repsonder for the text field - does that mean the textfield has taken control of the keyboard and wont release it until specifically told to?
My .h has:
@interface SearchItems : UIViewController {
IBOutlet UIButton *btnKeyboard;
IBOutlet UITextField *txtWhat;
IBOutlet UITextField *txtWhere;
}
@property (nonatomic, retain) IBOutlet UIButton *btnKeyboard;
@property (nonatomic, retain) IBOutlet UITextField *txtWhat;
@property (nonatomic, retain) IBOutlet UITextField *txtWhere;
-(IBAction)closeKeyboard;
@end
The .m (cut down)
@synthesize btnKeyboard, txtWhat, txtWhere;
-(IBAction)closeKeyboard {
[txtWhere resignFirstResponder];
[txtWhat resignFirstResponder];
}
Which isn't working, any ideas?
Thanks
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用委托方法来resignResponder:
除了这个之外,您还可以使用这个委托方法:
这两种方法主要应该能够解决您的键盘隐藏问题,而不是使用背景按钮技术。
Try using the delegate methods to resignResponder:
Apart from this one you can also use this delegate method:
These two methods mainly should be able to solve your keyboard hiding problem rather than using the background button technique.