表视图不根据绑定更新 - 第二部分 [英] Table view not updating according to bindings - Part Two

查看:162
本文介绍了表视图不根据绑定更新 - 第二部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题借用的标题,其中的一个是不是重复。看到我的答案有什么错误的提问者;我是这个答案的作者,我的问题不是那个。



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



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

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

NSLog 语句运行,并确认阵列控制器正在收集和排列我的模型对象。这意味着我将通过我的财产,并获得KVO通知我的文档(这证明早先的提问者的问题,绕过属性,是不是我遇到的问题)。



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



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


<我发现了问题:这是因为我明确绑定了 selectionIndexes sortDescriptors



这不是必须的,反正我只是选中了,而且文档说:


selectionIndexes



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



sortDescriptors h3>

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


看起来不仅不是必要的,而且绑定这两个或两个都会破坏表视图。


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.

解决方案

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.

这篇关于表视图不根据绑定更新 - 第二部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆