Table view not updating according to bindings - Part Two

女生的网名这么多〃 提交于 2019-12-11 01:54:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1934641/table-view-not-updating-according-to-bindings-part-two

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!