表视图未根据绑定进行更新 - 第二部分

发布于 2024-08-15 20:41:47 字数 973 浏览 1 评论 0原文

标题借自这个问题,其中这个是不是重复的。请参阅我的回答,了解该提问者出了什么问题;我是该答案的作者,我的问题不是这个。

我有一个包含三列的表视图,其值绑定绑定到数组控制器的 arrangedObjects 的三个属性。数组控制器的 contentArray 绑定到我的文档对象的 visitationResults;该数组中的项目是模型类 (VisitationResult) 的实例。我还将数组控制器的 selectionIndexessortDescriptors 绑定到我的文档的属性。

我通过几个访问器改变我的属性:

- (void) addVisitationResult:(VisitationResult *)newVisitationResult {
    [self insertObject:newVisitationResult inVisitationResultsAtIndex:[self countOfVisitationResults]];
    NSLog(@"arrayController arrangedObjects: %@", [arrayController arrangedObjects]);
}

NSLog 语句运行,并确认数组控制器正在收集和排列我的模型对象。这意味着我正在检查我的财产并获取我的文档的 KVO 通知(这证明了先前提问者的问题,即绕过财产的问题,不是我遇到的问题)。

我在模型对象类的访问器方法中添加了 NSLog 语句。其中之一由数组控制器调用,以便对对象进行排序(该属性是排序键)。数组控制器不知道的另外两个永远不会被调用。

因此,我的表格视图仍然是空白的。

Title borrowed from this question, of which this one is not a duplicate. See my answer there for what was wrong for that questioner; I'm the author of that answer, and my problem is not that one.

I have a table view with three columns, whose Value bindings are bound to three properties of the arrangedObjects of an array controller. The array controller's contentArray is bound to the visitationResults of my document object; the items in that array are instances of a model class (VisitationResult). I have also bound the array controller's selectionIndexes and sortDescriptors to properties of my document.

I am mutating my property through a couple of accessors:

- (void) addVisitationResult:(VisitationResult *)newVisitationResult {
    [self insertObject:newVisitationResult inVisitationResultsAtIndex:[self countOfVisitationResults]];
    NSLog(@"arrayController arrangedObjects: %@", [arrayController arrangedObjects]);
}

That NSLog statement runs, and confirms that the array controller is gathering and arranging my model objects. This means that I am going through my property and getting KVO notifications for my document (which proves that the earlier questioner's problem, that of bypassing the property, is not the problem I'm having).

I added NSLog statements in my model object class's accessor methods. One of them is being called—by the array controller, in order to sort the objects (that property is the sort key). The other two, which the array controller doesn't know about, never get called.

Thus, my table view remains blank.

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

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

发布评论

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

评论(1

差↓一点笑了 2024-08-22 20:41:47

我发现了问题:这是因为我显式绑定了表视图的 selectionIndexessortDescriptors 绑定。

无论如何,这是没有必要的:我刚刚检查过,并且 文档 说:

选择索引

通常,selectionIndexes 会自动绑定到第一个 NSTableColumn 所绑定的 NSArrayController。

排序描述符

通常这个绑定是自动创建的,绑定到最初绑定的 NSTableColumn 的 NSArrayController 的排序描述符。

看起来不仅没有必要,而且绑定这两者之一或两者都会破坏表视图。

I found the problem: It's because I had explicitly bound the selectionIndexes and sortDescriptors bindings of the table view.

This wasn't necessary, anyway: I just checked, and the documentation says:

selectionIndexes

Typically, selectionIndexes is bound automatically to the NSArrayController that the first NSTableColumn is bound to.

sortDescriptors

Typically this binding is created automatically, binding to the sort descriptors of the NSArrayController of the initially bound NSTableColumn.

It appears that not only is it not necessary, but binding either or both of these two will break the table view.

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