表视图未根据绑定进行更新 - 第二部分
标题借自这个问题,其中这个是不是重复的。请参阅我的回答,了解该提问者出了什么问题;我是该答案的作者,我的问题不是这个。
我有一个包含三列的表视图,其值绑定绑定到数组控制器的 arrangedObjects
的三个属性。数组控制器的 contentArray
绑定到我的文档对象的 visitationResults
;该数组中的项目是模型类 (VisitationResult) 的实例。我还将数组控制器的 selectionIndexes
和 sortDescriptors
绑定到我的文档的属性。
我通过几个访问器改变我的属性:
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题:这是因为我显式绑定了表视图的
selectionIndexes
和sortDescriptors
绑定。无论如何,这是没有必要的:我刚刚检查过,并且 文档 说:
看起来不仅没有必要,而且绑定这两者之一或两者都会破坏表视图。
I found the problem: It's because I had explicitly bound the
selectionIndexes
andsortDescriptors
bindings of the table view.This wasn't necessary, anyway: I just checked, and the documentation says:
It appears that not only is it not necessary, but binding either or both of these two will break the table view.