如何访问另一个xib中属于MyDocument的NSArray实例?

发布于 2024-11-07 21:05:58 字数 1277 浏览 0 评论 0原文

在我的文档应用程序中,我对 NSArrayController 进行了子类化,我在 MyDocument.xib 中引用了它,将其内容绑定到 File's Owner.entries

Entry 是一个 NSArray,我以这种方式公开为 MyDocument 类的属性:

@interface MyDocument : NSDocument {
    NSArray *entries;
}

-(NSArray *)entries;
-(void)setEntries:(NSArray *)newEntries;
@end

这工作得很好。好的。

现在我设计了另一个 .xib,CSVEntries.xib,我通过 NSWindowController 通过 NSMenuItem 打开它,并且工作顺利。

我不知道如何让这个新窗口显示 NSTableView 中 MyDocument.entries 实例的内容。

我已经尝试了很多东西,但问题基本上是我放在 CSVEntries.xib 上的任何 NSArrayController 都不能绑定到 MyDocument.entries:CVSEntries.xib 文件的所有者指的是其他不是 MyDocument 的东西(我想这是合乎逻辑的)。

我还尝试将 NSArray 实例的副本添加到打开 CVSEntries.xib 的 NSWindowController 中,但由于仅当用户单击菜单时才会实例化窗口,因此我最终得到了一个空数组。

我在互联网上搜索但找不到合适的答案,我只是想找出解决该问题的正确方法,我确信两个窗口可以相互通信,也许访问它们的共同父级( NSApplication 实例)?

所有新手问题,我知道:)

更新

我想我知道在哪里看,但仍然不知道如何看。我想我必须确保第二个窗口文件的所有者是 MyDocument 但在 NSWindowController initWithWindowNibName:owner: 我无法理解如何将 MyDocument 实例指定为所有者。仅在 xib 文件文件所有者中指定它似乎还不够。

更新 2

嗯...我开始认为我需要有两个 NSWindowController 实例,它们都由我的 NSDocument 子类(默认 MyDocument)实例化。有了这些,也许两个 NSWindowController 都可以访问 MyDocument.entries NSArray,并且两个窗口 xib 文件将能够绑定到文件的 Owner.entries。

有人可以证实这一点吗?谢谢。

In my document application I subclassed an NSArrayController which I referenced in MyDocument.xib bounding its content to File's Owner.entries.

entries is an NSArray I expose as an attribute of MyDocument class this way:

@interface MyDocument : NSDocument {
    NSArray *entries;
}

-(NSArray *)entries;
-(void)setEntries:(NSArray *)newEntries;
@end

This works perfectly fine. Good.

Now I have designed another .xib, CSVEntries.xib which I open via a NSMenuItem through a NSWindowController and again, this works smoothly.

I can't figure out how to make this new window display the content of the MyDocument.entries instance in an NSTableView.

I have tried many things, but the problem basically is that any NSArrayController I put on CSVEntries.xib can not be bound to MyDocument.entries: CVSEntries.xib File's Owner is referring to something else not MyDocument (which is logical, I guess).

I also tried to add a copy of the NSArray instance to the NSWindowController which opens CVSEntries.xib, but since the window get's instantiated only when the user clicks on the menu, I ended up having an empty array.

I am searched around the Internet but could not find an appropriate answer, I just would like to figure out the proper way to approach the issue, I am sure two windows can communicate between eachother, maybe accessing their common parent (NSApplication instance)?

All newbie questions, I know :)

Update

I think I figured out where to look but still not how to. I think I have to make sure second window File's Owner is MyDocument but in the NSWindowController initWithWindowNibName:owner: I can't understand how to specify the MyDocument instance as the owner. Specifying it only in the xib file File's Owner seems not enough.

Update 2

Uhm...I am starting to think that I need to have two NSWindowController instances both instantiated by my NSDocument subclass (default MyDocument). With those in place maybe both the NSWindowControllers will have access to the MyDocument.entries NSArray and the two windows xib files will be able to be bound to File's Owner.entries.

Can someone confirm this? Thanks.

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

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

发布评论

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

评论(1

Hello爱情风 2024-11-14 21:05:58

我在这里回答我自己的问题,基本上是说我已经意识到我所问的问题很大程度上取决于文件所有者的绑定。我实施的设计不正确,因此我正在重新设计它以实现我的目的。

无论如何,谢谢大家,即使没有答案也是答案:)

I reply to my own question here, basically stating that I have realized what I was asking is very much dependent on what the File's Owner is bound to. The design I implemented was not correct and I am therefore redesigning it to achieve my purpose.

Thanks everyone anyway, even no answers are an answer :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文