Domanda

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?

È stato utile?

Soluzione

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}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top