绑定包含 NSPopUpButtons 的表列

发布于 2024-08-08 06:21:27 字数 661 浏览 5 评论 0 原文

我有一个表,其中一列使用 NSPopUpButtonCell。尽管我尽了最大努力,但我似乎无法找出按照我想要的方式正确绑定所有内容的方法。这就是我想要做的:

我有一个 NSArrayController 从托管对象上下文中提取项目,称为“字段值”。这将用于填充每个项目的弹出菜单(即可用选项列表)。我可以通过选择 IB 中的单元格并将其内容/对象/值绑定到 'Field Values'.arrangedObjects 和 'Field Values'.arrangedObjects.name (以获取表示的对象和可见标题)来绑定它。

然后,我想以这样的方式绑定列,即每行中的选定值来自我的控制器类中的数组,再次使其可见(并且只能通过另一个 NSArrayController 进行编辑)。

到目前为止,我已经成功地进行了设置,以便每个弹出菜单都包含可用字段的列表,并且在每个弹出菜单中都选择了默认值。然而,实际上选择一个项目没有任何效果——它只是恢复到其初始值。我还设法找到了一些其他变体,例如用所选值填充的菜单,或包含所有可用值的名称,以及包含“的 -description 的选择”我没有添加任何价值。

我确信我错过了一些相当简单的东西,但我不确定它是什么。想必在如何绑定此类数据(即内容与内容对象与内容值的事情)方面我错过了一些微妙之处,但如果我现在能看到它,我就该死了。

非常感谢提前:o)

I've got a table one column of which uses an NSPopUpButtonCell. Try as I might, I can't seem to figure out the way to properly bind everything the way I want it. Here's what I'm trying to do:

I have an NSArrayController plucking items from a managed object context, called 'Field Values'. This is to be used to populate the popup menu for each item (i.e. the list of available choices). I can bind this by selecting the cell in IB and binding its content/objects/values to 'Field Values'.arrangedObjects and 'Field Values'.arrangedObjects.name as appropriate (to get the represented object and the visible title).

I then want to bind the column in such a way that the selected value in each row comes from an array in my controller class, again made visible (and only edited through) another NSArrayController.

So far I've managed to set it up so that every popup menu contains the list of available fields, and that the default value is selected in each of them. Actually selecting an item has no effect, however— it just snaps back to its initial value. I've also managed to find some other variations on this, such as the menu being populated with the selected values, or containing the name of all available values, and the selection containing the -description of the 'none' value I added.

I'm sure I'm missing something fairly simple, but I'm not sure what it is. Presumably there's some subtlety I've missed in how to bind this sort of data (i.e. the Content vs. Content Object vs. Content Value things), but I'm damned if I can see it right now.

Many thanks in advance :o)

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

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

发布评论

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

评论(2

娇俏 2024-08-15 06:21:27

我有一个类似的表视图设置,虽然数据源不是基于核心数据的,但我看到一件事你可能会仔细检查,这可能是一个微妙的差异。在表列的设置中,我通过 content、contentValues 和 selectedObject 绑定了表列本身。但是,看起来也可以在实际的 NSPopUpButtonCell 上进行绑定。也许当绑定位于表列上时它可以工作,但当它们位于实际单元格上时则不起作用?无论如何,有一件事可能值得研究。

I've got a similar set up with a table view, although the data source isn't Core Data based, but I saw one thing you might double check that could be a subtle difference. In my setup for the table column, I have the table column itself bound via content, contentValues, and selectedObject. However, it looks like it's also possible to do the bindings on the actual NSPopUpButtonCell instead. Perhaps it works when the bindings are on the table column, but not when they're on the actual cell? Anyway, there's one thing that might be worth looking into.

逆夏时光 2024-08-15 06:21:27

切勿绑定到滚动视图、表格视图或单元格。
但是,必须绑定到表列。

观察检查器窗口的标题以确定您正在绑定的内容。

Never bind to scroll view, table view or cell.
However, ever bind to table columns.

Watch the title of the Inspector window to be certain of what you're binding.

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