单击 UITextField 时如何调用方法?
我想问,当我在 iphone UITextField 中单击(触摸开始写入)时,如何调用方法,就像我们单击 UIButton 并将方法放入“addTarget”中一样,UITextFields 有什么办法吗?
I want to ask that how can I call a method as I do click(touch for start writing) in iphone UITextField, as like we click UIButton and put method in "addTarget", is there any way for UITextFields ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实现 UITextFieldDelegate 并执行您想做的任何操作
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
或- (void)textFieldDidBeginEditing:(UITextField *)textField
如果要停止文本字段,应使用第一种方法从表现得像一个文本字段。例如,如果您想在模式视图中打开文本字段编辑器。如果您不希望出现这种行为,可以在那里返回 NO。
编辑:这是调用 myMethod 的代码:
implement a UITextFieldDelegate and do whatever you want to do in
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
or- (void)textFieldDidBeginEditing:(UITextField *)textField
You should use the first method if you want to stop the textfield from behaving like a textfield. For example if you want to open the textfield editor in a modal view. You can return NO there if you don't want this behavior.
Edit: Here is the code to call myMethod:
您可以设置 textField 的委托并在其中实现
textFieldShouldBeginEditing:
方法 - 当用户点击该字段时以及进入编辑之前,该方法将被调用。有关更多可用方法,请参阅
UITextFieldDelegate
参考。You can set textField's delegate and implement
textFieldShouldBeginEditing:
method in it - that method will get called when user taps the field and before it goes into editing.See
UITextFieldDelegate
reference for more methods available.我认为这会有所帮助..!!
i think this will help..!!
您可以编码为,
You can code as,