Question

I'm trying to do this:

- (IBAction)textFieldSelected:(id)sender
{
    printf("clicou no text\n");
}

I "connect" this to my NSTextField through the Interface Builder.

When I first start the app, the this NSTextField is already focused. Then I click on a second NSTextField, and my first one lose the focus and I get the print statement. Clicking back and forth between theses NSTextField I see that the print statement is just called when I click on the NSTextField that it is not attached to it. I believe that it just happens when the first one loses the focus.

Q1: How do I do to have this print statement when the use click on the NSTextField (when it gets the focus)?

Q2: How do I avoid it to get the focus automatically when the app starts?

Was it helpful?

Solution

Create the custom class of NSTextfield and then implement below method, so that whenever focus goes to the textfield below method will get called:-

   -(Bool)becomeFirstResponder{
     return YES}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top