Nested NSViews and keyboard focus

  • The installer I'm working on has a main window containing a few push
    buttons and an NSBox. As the user moves through the installer, I use the
    setContentView method on the NSBox to replace the contents of the box
    with the view for the current "panel" of the install. These panels are
    really just grouping of other standard controls and are implemented as
    custom NSViews in IB. Some of these panels contain multiple text fields.
    There are 2 problems I am seeing.

    1. I cannot get any of the NSTextFields to automatically become the
    first responder in the window after switching the NSBox's content view.
    2. Hitting TAB in one of the NSTextFields on the custom view does not
    move to the next one.

    I've tried using various combinations of overriding canBecomeKeyView and
    acceptsFirstResponder on my custom view but it doesn't seem to make any
    difference. I'm new to Cocoa, so I'm sure I'm just missing something
    obvious. Is using a custom NSView in this case even the right thing to
    do? I just need to have a way to represent a grouping of controls in IB
    that I can swap in and out of the main window as appropriate.

    Thanks,
    -Nathan
  • On Dec 21, 2007, at 10:52, Nathan Auch wrote:

    > The installer I'm working on has a main window containing a few push
    > buttons and an NSBox. As the user moves through the installer, I use
    > the setContentView method on the NSBox to replace the contents of
    > the box with the view for the current "panel" of the install. These
    > panels are really just grouping of other standard controls and are
    > implemented as custom NSViews in IB. Some of these panels contain
    > multiple text fields. There are 2 problems I am seeing.
    >
    > 1. I cannot get any of the NSTextFields to automatically become the
    > first responder in the window after switching the NSBox's content
    > view.
    > 2. Hitting TAB in one of the NSTextFields on the custom view does
    > not move to the next one.
    >
    > I've tried using various combinations of overriding canBecomeKeyView
    > and acceptsFirstResponder on my custom view but it doesn't seem to
    > make any difference. I'm new to Cocoa, so I'm sure I'm just missing
    > something obvious. Is using a custom NSView in this case even the
    > right thing to do? I just need to have a way to represent a grouping
    > of controls in IB that I can swap in and out of the main window as
    > appropriate.

    What about using a tab-less NSTabView? Or you might want to look at
    NSWindow's recalculateKeyViewLoop or setAutorecalculatesKeyViewLoop.

    -Jacob
  • Jacob Lukas wrote:
    > On Dec 21, 2007, at 10:52, Nathan Auch wrote:
    >
    >> The installer I'm working on has a main window containing a few push
    >> buttons and an NSBox. As the user moves through the installer, I use
    >> the setContentView method on the NSBox to replace the contents of the
    >> box with the view for the current "panel" of the install. These
    >> panels are really just grouping of other standard controls and are
    >> implemented as custom NSViews in IB. Some of these panels contain
    >> multiple text fields. There are 2 problems I am seeing.
    >>
    >> 1. I cannot get any of the NSTextFields to automatically become the
    >> first responder in the window after switching the NSBox's content view.
    >> 2. Hitting TAB in one of the NSTextFields on the custom view does not
    >> move to the next one.
    >>
    >> I've tried using various combinations of overriding canBecomeKeyView
    >> and acceptsFirstResponder on my custom view but it doesn't seem to
    >> make any difference. I'm new to Cocoa, so I'm sure I'm just missing
    >> something obvious. Is using a custom NSView in this case even the
    >> right thing to do? I just need to have a way to represent a grouping
    >> of controls in IB that I can swap in and out of the main window as
    >> appropriate.
    >
    > What about using a tab-less NSTabView? Or you might want to look at
    > NSWindow's recalculateKeyViewLoop or setAutorecalculatesKeyViewLoop.
    >
    > -Jacob
    >
    Thanks Jacob,

    recalculateKeyViewLoop fixes #2 above, but I'm still stuck with how to
    make the NSTextField that I want automatically become the first
    responder of the window. Is this something I just need to do manually?

    -Nathan
previous month december 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
31            
Go to today