我应该使用哪个委托方法来响应对文本字段的点击? [英] Which delegate method I should use to respond to clicks on a text field?
问题描述
当用户点击文本字段时,我想打开一个面板。我想我应该使用一个委托方法来响应点击事件。我发现
I want to open a panel when the user clicks on a text field. I think I should use a delegate method that responds to the click event. I found that the
- (void)textDidBeginEditing:(NSNotification *)aNotification
方法不起作用,并且
- (void)controlTextDidBeginEditing:(NSNotification *)aNotification
在文本字段中,不是我单击它。如果我再次编辑文本,此方法不工作。为什么?
method works, but only when I edit the text in the text field, not then I click it. If I edit the text again, this method does not work. Why?
对不起,我想在mac上使用,而不是在iphone上,可可?
Sorry, I think I want to use this on mac , not on iphone,How to do with it with cocoa?
推荐答案
textFieldDidBeginEditing:
用户开始编辑 UITextField
中的文本,如方法名称所示。
The textFieldDidBeginEditing:
delegate method only gets triggered when the user starts editing the text inside the UITextField
, as the method name implies.
如果要触发方法当触摸 UITextField
时,应该尝试:
If you want to trigger a method when the UITextField
is touched, you should try this:
[textField addTarget:self
action:@selector(textFieldTouched:)
forControlEvents:UIControlEventTouchDown];
- (void) textFieldTouched:(id)sender {
// Display the panel
}
这篇关于我应该使用哪个委托方法来响应对文本字段的点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!