gpt4 book ai didi

cocoa - 绑定(bind)到 NSViewController 的representedObject

转载 作者:行者123 更新时间:2023-12-03 16:15:11 29 4
gpt4 key购买 nike

(摘要:绑定(bind)在代码中起作用,但在 IB 中不起作用)

我有一个由 NSWindowController 管理的窗口。窗口左侧是源 View 。右侧是一个表格 View ,显示当前所选源的元素。

我已经在我的窗口 XIB 中设置了一个 NSTreeController。我希望将其内容用于源 View 。它的选择将驱动表格 View 。

我正在尝试使用 NSViewControllers 来分割它。一个 View Controller 将加载包含源 View 的 NIB。另一个 View Controller 将加载 TableView 。

看到我需要访问源 View Controller 中的 NSTreeController,我已将其设置为 View Controller 的representedObject。 (实际上,为了在 View Controller 上调用 awakeFromNib 时完成此设置,我已将representedObject 转换为 IBOutlet)。

当我在代码中连接源 View 时,一切正常:

[outlineView bind:@"content"
toObject:sources
withKeyPath:@"arrangedObjects"
options:nil];
[outlineView bind:@"selectionIndexPaths"
toObject:sources
withKeyPath:@"selectionIndexPaths"
options:nil];
[[outlineView tableColumnWithIdentifier:@"Title"] bind:@"value"
toObject:sources
withKeyPath:@"arrangedObjects.title"
options:nil];

但是,我无法使用 Interface Builder 重现此情况。问题是,这里的“ Controller 键”文本字段呈灰色。因此,我使用“representedObject.arrangedObjects.title”模型 keyPath 将列的“值”绑定(bind)到文件所有者。这没有显示出所需的行为。实际上抛出了一个异常:-[NSProxy doesNotRecognizeSelector:_mutatingNodes]被调用!

如何在IB中使用representedObject?我可以在 IB 中创建一个 Controller 来充当representedObject 的代理吗?我可以在源 View XIB 中设置一个树 Controller ,在 NIB 加载期间将其替换为所表示的对象吗?

最佳答案

我不再使用representedObject。看来这仅适用于模型对象。

我现在使用自定义 socket 传入我的树 Controller 。我继续在代码中设置和拆除绑定(bind)。

关于cocoa - 绑定(bind)到 NSViewController 的representedObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1514276/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com