1
votes

I have to upgrade one existing application and neeed to split its existing UI into separate NIBs. I have planning to start with creating separate NIBs and NSViewController for all my splitted UIs. Now the problem is my NSViewController didn't respond on keyboard TAB and SHFIT+TAB events, I simply wants my NSViewController to set focus on appropriate child control in my dynamically loaded NSViewController view when user click TAB or SHIFT+TAB.

Thanks,

EDITED : Following is my requirement.

I have three sub views which i need to load dynamically and switch using NSPopupButton in my MainWindow placeholder NSBox.

For checking i have created new cocoa app and added one NSPopupButton and NSBox to Window and join the outlets for NSPopupButton and NSBox.

Second, I have created three new NSViewController's with three different NIB's containing separate custom view containing two or three NSTextField's child controls.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}

In the main app delegate function i am adding all the three NSViewController's to an array and later swapping of views using replaceSubview to replace views in placeholder NSBox.

I have added following code in all the three NSViewController's, but i am still not getting focus on child controls by pressing TAB or SHIFT+tab keys.

- (void)loadView {
    [super loadView];

    // store the responder that’s right after the view in the responder chain
    NSResponder *nextResponder = [[self view] nextResponder];

    // set the view controller (self) as the next responder after the view
    [[self view] setNextResponder:self];

    // set the stored responder as the next responder after the view controller
    [self setNextResponder:nextResponder];
}
1
In addition i have also join nextKetView to first NSTextField of every custom view in all the three NIB'sAmitSri

1 Answers

2
votes

Even though NSViewController inherits from NSResponder, Cocoa doesn’t automatically add NSViewController instances to the responder chain. You need to do it yourself.

One possible solution is to insert your view controller into the responder chain between the view it is controlling and the next responder of that view. For instance, in your view controller implementation,

- (void)loadView {
    [super loadView];

    // store the responder that’s right after the view in the responder chain
    NSResponder *nextResponder = [[self view] nextResponder];

    // set the view controller (self) as the next responder after the view
    [[self view] setNextResponder:self];

    // set the stored responder as the next responder after the view controller
    [self setNextResponder:nextResponder];
}