Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 如何使视图的子控件集中在Tab和Shift+;NSViewController中的选项卡_Cocoa_Nsviewcontroller - Fatal编程技术网

Cocoa 如何使视图的子控件集中在Tab和Shift+;NSViewController中的选项卡

Cocoa 如何使视图的子控件集中在Tab和Shift+;NSViewController中的选项卡,cocoa,nsviewcontroller,Cocoa,Nsviewcontroller,我必须升级一个现有的应用程序,并需要将其现有的UI拆分为单独的NIB。我计划首先为所有拆分的UI创建单独的NIB和NSViewController。现在的问题是,我的NSViewController没有对键盘选项卡和SHFIT+选项卡事件做出响应,我只是想让我的NSViewController在用户单击TAB或SHIFT+TAB时,将焦点设置在动态加载的NSViewController视图中相应的子控件上 谢谢 编辑: 以下是我的要求 我有三个子视图需要动态加载,并在主窗口占位符NSBox中使用

我必须升级一个现有的应用程序,并需要将其现有的UI拆分为单独的NIB。我计划首先为所有拆分的UI创建单独的NIB和NSViewController。现在的问题是,我的NSViewController没有对键盘选项卡和SHFIT+选项卡事件做出响应,我只是想让我的NSViewController在用户单击TAB或SHIFT+TAB时,将焦点设置在动态加载的NSViewController视图中相应的子控件上

谢谢

编辑: 以下是我的要求

我有三个子视图需要动态加载,并在主窗口占位符NSBox中使用NSPopupButton进行切换

为了进行检查,我创建了新的cocoa应用程序,并在窗口中添加了一个NspupButton和NSBox,并加入了NSPopupButton和NSBox的插座

其次,我创建了三个新的NSViewController,其中三个不同的NIB包含单独的自定义视图,其中包含两个或三个NSTextField的子控件

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
在主应用程序委派功能中,我将所有三个NSViewController添加到一个数组中,然后使用replaceSubview替换占位符NSBox中的视图

我在所有三个NSViewController中都添加了以下代码,但我仍然没有通过按TAB键或SHIFT+TAB键来关注子控件

- (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];
}

即使
NSViewController
继承自
NSResponder
,Cocoa也不会自动将
NSViewController
实例添加到。你需要自己做

一种可能的解决方案是将视图控制器插入其控制的视图和该视图的下一个响应者之间的响应者链中。例如,在视图控制器实现中

- (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];
}

嗨,谢谢你的回答。我已经用更具体的要求编辑了我的问题。请看一看并向我建议解决方案。@AmitSri在替换子视图时,您需要在响应者链中插入视图控制器。别忘了从响应程序链中删除以前的视图控制器。我感谢您的帮助,让我知道您是否会为我提供上述要求的一些链接或示例代码。此外,我还将nextKetView加入到所有三个NIB中每个自定义视图的第一个NSTextField