派生自 NSTabViewItem

发布于 2024-08-19 11:20:44 字数 514 浏览 3 评论 0原文

我正在写一个 Cocoa 应用程序。一个对话框有3个选项卡,有些选项卡需要更多加载时间,所以我想延迟加载它们。由于每个选项卡都是一个 NSTabViewItem 类,因此我尝试从它派生并覆盖它的 view 属性。在视图 getter 方法中,我使用 ViewController 加载视图并返回。在调试中,我发现 NSTabViewItem -view 方法被正确调用,但之后 NSTabView 尝试设置初始 FirstResponder 并崩溃并显示消息:

*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“在 -[NSTabViewItem setInitialFirstResponder”中: ],第一响应者必须从选项卡视图项的视图下降。 (项目:无效的响应者:)'

我尝试重写 -initialFirstResponder 方法以返回已加载视图的子视图,但它仍然在同一位置崩溃。

有谁知道如何让它正常工作?通过派生 NSTabViewItem 来执行此操作是否正确?

谢谢! -乔尼

I'm writing a Cocoa app. One dialog has 3 tabs, some of the tabs needs more loading time, so I want to load them lazily. Since each Tab is a NSTabViewItem class, so I'm trying to derive from it and overriding its view property. In the view getter method, I use a ViewController to load a view and returns out. In Debugging, I found NSTabViewItem -view method is get called correctly, but after that NSTabView tries to set Initial FirstResponder and crashed with message:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'In -[NSTabViewItem setInitialFirstResponder:], the first responder must descend from the tab view item's view. (Item: Invalid responder: )'

I tried to override the -initialFirstResponder method to return a sub-view of my loaded view, but it still crashes the same place.

does anyone know how to get it work correctly? Also is it correct way to do this by deriving the NSTabViewItem?

thanks!
-Jonny

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷到爆炸 2024-08-26 11:20:44

好的,我现在明白了异常。 NSTabViewItem 有它的视图,所以我应该使用它的视图并将我的新视图添加为子视图,例如:

-(NSView*)view {
   NSView* view = [super view];
   NSVIew* myView = //load view from nib
   [view addSubView:myView];
   return view;
}

OK, I understand the exception now. The NSTabViewItem has its view, so I should use its view and add my new view as a subview, like:

-(NSView*)view {
   NSView* view = [super view];
   NSVIew* myView = //load view from nib
   [view addSubView:myView];
   return view;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文