0

I implemented a tabbar view as an NSControl subclass.

enter image description here

When I click it, AppKit will try to update the firstResponder of my NSWindow. Because I don't want the tabbar to become firstResponder (acceptsFirstResponder returns NO) the NSWindow itself will become the firstResponder. My responder chain will consist of the window and it's controller and no Action Messages are delivered to the subview below the tabbar (an NSOutlineView). I'd like the NSOutlineView to keep receiving Action Messages and Events when I click the tabbar.

What's the appropriate way to do this? Is there no way to stop an NSView from trying to change the firstResponder when being clicked on?

I thought about setting the toolbar's nextResponder to the NSOutlineView, but manually changing the nextResponder of an NSView is not recommended by Apple.

1 Answer 1

0

I ended up manually resetting the firstResponder to the outline view in my tabbar's delegate method implementation.

An other solution I came up with is implementing this in the tabbar to reset firstResponder to the original object, if the tabbar becomes the firstResponder.

- (void)awakeFromNib {
    [self.window addObserver:self
                  forKeyPath:@"firstResponder"
                     options:NSKeyValueObservingOptionOld
                     context:nil];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
                        change:(NSDictionary *)change context:(void *)context {
    NSResponder *oldResponder = [change objectForKey:NSKeyValueChangeOldKey];
    if (self.window.firstResponder == self) {
        [self.window makeFirstResponder:oldResponder];
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.