How to make child controls of view will get focus on Tab and Shift+Tab in NSViewController

核能气质少年 提交于 2019-12-07 23:15:31

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];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!