0

controlTextDidBeginEditing delegate method is not being called when NSTextfield is selected by clicking or by pressing tab.The delegate is set and all other delegate methods are fired.Any suggestions??

sujith1406
  • 2,822
  • 6
  • 40
  • 60
  • Post code snippet here. Another suggestion is to debug and verify that the text field is becoming first responder. – Raviprakash Oct 10 '13 at 05:36
  • 1
    hi i found out the problem later... actually this method gets fired only when we start editing or typing text into the textfield...otherwise it wont get fired...now i am searching for another method which gets fired when the textfield is selected itself... either by tab or mousedown – sujith1406 Oct 10 '13 at 05:38
  • You may be looking for this method `setFieldEditor:` – Raviprakash Oct 10 '13 at 05:46
  • ok thanks i were trying to subclass the nstextfield and write a custom delegate when the tab is pressed... for this in subclass i wrote the code like - (void)keyDown:(NSEvent *)theEvent { NSLog(@"keyPressed on TextField"); NSLog(@"%d",[theEvent keyCode]); //if(keycode==tabevent) //[self.delegate tabPressed]; } but even this method is not getting called keydown should work for all responders right? – sujith1406 Oct 10 '13 at 06:01
  • 1
    The method that is in my previous comment should be suffice. Whenever key event happens on a responder, `keyDown:` method should get called.If you are overriding `NSTextfield` then you can try implementing 'becomefirstresponder` method. – Raviprakash Oct 10 '13 at 06:35
  • 1
    hi thanks a lot ....it worked.. can you put it as the answer – sujith1406 Oct 10 '13 at 15:24

1 Answers1

1

To handle key events like Tab key press can be handled by writing setFieldEditor: method in the delegate method.For this requirement this method is suffice.

Another method is to override the NSTextfield class and writing keyDown: method.

Raviprakash
  • 2,410
  • 6
  • 34
  • 56