绑定出现问题,无法找出原因

发布于 2024-08-18 19:06:15 字数 371 浏览 4 评论 0原文

我有一个可变数组,用于保存模型对象的实例。该模型对象有几个属性,其中之一是“名称”。我在初始化或填充可变数组时没有任何问题。

我有一个带抽屉的窗户。我向抽屉添加了一个表格,其想法是抽屉将使用该表格来显示模型对象的多个实例。

我在有抽屉的窗口的 xib 中添加了一个 nsarraycontroller。在数组控制器属性中,我将对象控制器设置为模型类的实例。在数组控制器绑定上,我将控制器内容设置为指向文件所有者,并将模型密钥路径设置为数组的名称。

在表格上,我将内容绑定到数组控制器,将控制器密钥绑定到arrangedObjects,并将模型密钥路径绑定到名称。

我的问题是,尽管可变数组已正确初始化和填充,但我在抽屉的桌子上看不到任何条目。我在这里错过了什么吗?

I've a mutable array that holds instances of a model object. That model object has several properties one being "name". I have no problems initialising or populating the mutable array.

I've a window with a drawer. I added a table to the drawer, the idea being that the drawer would use the table to display several instances of the model object.

I added an nsarraycontroller to the xib of the window that has a drawer. In the Array Controller Properties I've set the Object Controller to be an instance of the model class. On the Array Controller Bindings I set the Controller Content to point to the File Owner and set the Model Key Path to the name of the array.

On the table, I bind the content to the Array Controller, the Controller Key to arrangedObjects and Model Key Path to name.

My problem is that although the mutable array has been properly initialised and populated I can't see a single entry on the table on the drawer. Am I missing something here?

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

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

发布评论

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

评论(2

胡大本事 2024-08-25 19:06:15

两种可能性:

第一:您可能绑定了错误的东西(您在这里的描述有点含糊)。将每个表列的“值”绑定到数组控制器的 @"arrangedObjects.propertyName" (如 First Name 列的arrangedObjects.firstName 等)。有其他方法可以绑定整个表,但您可能不会绑定的值,而只是绑定的内容。

第二:模型对象的访问器也可能不符合 KVO。确保正确的 KVO 通知包装模型数组的 setter 访问器。如果你已经@synthesize了,一切都应该没问题。如果您手动编码了访问器,那么一切可能都不太顺利。 :-)

Two possibilities:

First: you might have bound the wrong thing (your description here is a bit ambiguous). Bind each table column's "values" to the array controller's @"arrangedObjects.propertyName" (like arrangedObjects.firstName for the First Name column, etc.). There are alternative ways to bind the whole table, but you probably aren't binding the column's values, just the table's content.

Second: it's also possible the accessor to your model object isn't KVO compliant. Make sure proper KVO notifications wrap your setter accessor for your model array. If you've @synthesize'd it, all should be well. If you've hand-coded your accessors, all might not be well. :-)

一个人的旅程 2024-08-25 19:06:15

我假设您将 tablecells 表列绑定到数组控制器?我认为 Interface Builder 不会让你做任何其他事情。否则,听起来你已经正确配置了。

我会推荐 ibtool用于解决此类问题。它是一个执行文本转储的命令行工具。与使用 Interface Builder 中的 GUI 相比,您可以以更紧凑的形式检查绑定。

I assume you bound the tablecells table columns to the arraycontroller? I don't think Interface Builder will let you do anything else. Otherwise, it sounds like you have it configured properly.

I would recommend ibtool for troubleshooting these kinds of problems. It's a command line tool that does a text dump. You can inspect bindings in a more compact form than using the GUI in Interface Builder.

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