当用户点击键盘上的返回键时如何单击UIButton [英] How to click UIButton when user hits return on keyboard
本文介绍了当用户点击键盘上的返回键时如何单击UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够在用户触摸屏幕键盘上的回车键后立即发送消息.我有一个发送UIButton,如何让它侦听返回键? 谢谢!
I want to be able to send a message as soon as the user touches return on the on-screen keyboard. I have a send UIButton, how do I make it listen for the return key? Thanks!
推荐答案
您的按钮方法:
- (void) btnPressed:(id)sender {
{
如果没有,请添加委托资料
Add Delegate Stuff if you haven't
@interface YourViewController : UIViewController <UITextFieldDelegate>
当您调用textField时:
And when you call your textField:
yourTextField.delegate = self;
然后,您应该只在委托shouldReturn
方法中调用按钮的action方法:
Then, you should just call the button's action method in the delegate shouldReturn
method:
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[self btnPressed:nil];
// whatever else you need
return YES;
}
这篇关于当用户点击键盘上的返回键时如何单击UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文