Setting up the nextKeyView programmatically

  • hi dear group,
    as a cocoa newbee I'm stuck with the following problem:
    how do I set up the nextKeyView-order of a couple of NSTextFields
    programmatically, when each NSTextField is located inside its own
    NSClipView?

    the background:
    I have to use an existing framework that puts each NSTextField inside
    an NSClipView (for whatever reason). the fields/views are created
    programmatically, so I can't use IB to set up the nextKeyView.
    I want to make sure that tabbing between the Fields works as usual.
    Searching the web and the archives wasn't sucessful for the last
    days, so I hope somebody can help me here...
    thanks for any ideas or hints!
    regards,
    jan
  • On Sep 4, 2007, at 4:28 PM, Jan David Frölich wrote:

    > [H]ow do I set up the nextKeyView-order of a couple of NSTextFields
    > programmatically, when each NSTextField is located inside its own
    > NSClipView?
    ...
    > I want to make sure that tabbing between the Fields works as usual.
    > Searching the web and the archives wasn't sucessful for the last
    > days, so I hope somebody can help me here...

    You don't say whether you tried the setNextKeyView: method, and what
    the result was.

    — F
  • hi fritz,
    thanks for your answer!!!
    I had tried "setNextKeyView" before, but now I figured out what I had
    done wrong and it works like this:

    NSEnumerator* enumerator;
    NSView* subview;
    NSView* lastSubview = nil;

    enumerator = [[[mainWindow contentView] subviews] objectEnumerator];
    while( subview = [enumerator nextObject] )
    {
      if ([subview isKindOfClass:[NSClipView class]]) {
      if(lastSubview){
        [[[subview subviews] objectAtIndex:0] seKeyView:[[lastSubview
    subviews] objectAtIndex:0]];
      }
      lastSubview = subview;
      }
    }
    it still needs a little tweaking (jumping back from the last field to
    the first...) but this saves my day already....
    regards,
    jan
    > On Sep 4, 2007, at 4:28 PM, Jan David Frölich wrote:
    >
    >> [H]ow do I set up the nextKeyView-order of a couple of
    >> NSTextFields programmatically, when each NSTextField is located
    >> inside its own NSClipView?
    > ...
    >> I want to make sure that tabbing between the Fields works as usual.
    >> Searching the web and the archives wasn't sucessful for the last
    >> days, so I hope somebody can help me here...
    >
    > You don't say whether you tried the setNextKeyView: method, and
    > what the result was.
    >
    > — F
    >
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today