views:

231

answers:

3

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

method does not work, and that the

  • (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?

A: 

Good question.

+4  A: 

Since NSTextField inherits from the NSControl class, it also inherits the -(void)mouseDown:(NSEvent*) theEvent method.

Zach Gardner
I found that nstextfield inherits from the NSControl class , I also found that The NSController class have the method mouseDown ,but I don't know how to use it in my file, Thanks a lot .
jin
You can simply override the mouseDown event in the NSTextField class, as follows:@implementation NSTextField -(void)mouseDown:(NSEvent*) theEvent { // your code here}@end
Zach Gardner
A: 

sorry ,Can you explain it in details? or if you can give me some code to reach it . I am a greenhand , thank you very much. Because I take the textfield a object in the class of subclass NSWindowController. under this situation, how to implement the mouseDown method . I found that nstextfield inherits from the NSControl class , I also found that The NSController class have the method mouseDown ,but I don't know how to use it in my file, Thanks a lot .

jin