makeFirstResponder not responding!

Discussion in 'Mac Programming' started by paos, Aug 13, 2009.

  1. paos macrumors newbie

    Aug 13, 2009

    I have two simple views which are displayed in a window, the first one has a button with this action:

    	SecondView *testview = [[SecondView alloc] initWithFrame:NSZeroRect];
    	[[self window] setContentView:testview];
    	[testview release];
    It works ok, but on the second view I have two textfields and I use this on init:

    [[self window] makeFirstResponder: myTextField];
    and myTextField doesnt appear selected, when I select it with the mouse I can edit it but , I can't move to the next textField using Tab on keyboard, I dont know wath I'm missing, please help.
  2. petron macrumors member

    May 22, 2009
    Malmo, Sweden
    Hi Paos
    Try to make a close look into the Interface Builder again.
    The reason that it does not work may be that the connections in the IB are not specified or are wrongly specified. Please go through each element in your window and check the connections.
    I have some running examples at home and I will look at it when back home tonight. Maybe then I can give you more help.
  3. paos thread starter macrumors newbie

    Aug 13, 2009
    After checking my connections I realized that Tab works after pressing Ctrl-Tab, any idea why is this happening?? thanks!
  4. kainjow Moderator emeritus


    Jun 15, 2000
    Most likely the nib hasn't yet been created yet at the init method, so you would either need to force it to load immediately, or put your code in the awakeFromNib method.
  5. petron macrumors member

    May 22, 2009
    Malmo, Sweden
    It seems strange.... I do not know about your program but in my case I have a NSView and three NSTextFields.

    Here is what I do:
    For the NSView I do run
    NSResponder *resp = [[self window] firstResponder];
    when the NSView is created.

    Implement in the NSView handling of

    - (BOOL)acceptsFirstResponder
    - (BOOL)resignFirstResponder
    - (BOOL)becomeFirstResponder

    In the Interface builder I have to specify the
    nextKeyView in serial connection, it means that NSView object points to the First NSTextView, then first NSTextView nextKeyView point into the Second NSTextView... and so on.

    Hope it will explain the mechanism.
    Good luck

Share This Page