NSTextField focus don't work if is added programmatically

Discussion in 'Mac Programming' started by Ivang, Sep 30, 2013.

  1. Ivang macrumors newbie

    Joined:
    Sep 30, 2013
    #1
    Hi, I have a window with 4 nstextfield, 2 added in xib and 2 added programmatically.
    The focus change between the two added in xib with tab, but never change the focus to the 2 added programmatically.
    In the link I added a very simple example for a better understanding.

    https://www.dropbox.com/s/xsogsspfp1idc2j/Test.zip

    I'm very beginner in OS X and I think the solution is really easy, but no idea how do it.

    Thanx
    Ivan
     
  2. larswik macrumors 68000

    Joined:
    Sep 8, 2006
  3. Ivang thread starter macrumors newbie

    Joined:
    Sep 30, 2013
    #3
    When the focus is in the NsTextField added in xib, I push the key TAB and the focus never is in the NSTextField added programmatically.

    Thanx
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    I think what you need to do is use the method setNextResponder:

    IE,

    Code:
    textField1.nextResponder = textField2;
     
  5. Ivang thread starter macrumors newbie

    Joined:
    Sep 30, 2013
    #5
    I use this code:

    Code:
    NSTextField *campo1 = [[NSTextField alloc] initWithFrame:CGRectMake(30, 130, 100, 22)];
    NSTextField *campo2 = [[NSTextField alloc] initWithFrame:CGRectMake(150, 130, 100, 22)];
    [self.view addSubview:campo1];
    [self.view addSubview:campo2];
    campo1.nextResponder = campo2;
    
    When the focus is in campo1, the focus don't change with the key TAB, I think this don't work.

    Thanx.
     
  6. Ivang thread starter macrumors newbie

    Joined:
    Sep 30, 2013
    #6
    Ok, all done.

    nextResponder don't work for me, but nextKeyView, works perfect.

    Thanx.
     

Share This Page