开发者

Binding NSOutlineView's selection index paths

I have a custom <NSOutlineViewDataSource>, for which I would its NSOutlineView to update a selectionIndexPaths property. I can't get bind:toObject:withKeyPath:options: to actually bind properly. Basically, I need my data source to know which item is selected.

When I bind to sele开发者_开发百科ctionIndexes (declared by NSTableView) or selectionIndexPaths (declared by NSOutlineView), which the documentation indicates I should be able to (unless for some reason that's only available in IB), I get a runtime exception that the outline view isn't "key value coding-compliant" for either of those keys.

When I bind to selectedRowIndexes (a fallback, since I would need to then take that information and reverse-engineer it to figure out which parent/child pair is selected), it updates the data source once, with the NSIndexSet in the data source frozen to its initial value. I don't set it manually, either. Further, I can't even bind selectedRowIndexes in the other direction, so the data source can update the outline view's selection. I get the same "key value coding-compliant" exception on the outline view.

I have an @property defined in my data source class, with a backing ivar, and I'm binding it from a controller class with references to the data source and the outline view, after data has been loaded, in -awakeFromNib.


Dov, have you considered using NSTreeController which is tailored to bindings? Alternatively, You can set your controller as the delegate of the outline view to receive notification of a selection with the method "-outlineViewSelectionDidChange"

Source


Rather than binding selectionIndexPaths, which acted unreliably, I instead used my outline view's delegate to update the selection in the model on the -outlineViewSelectionIsChanging: and -outlineViewSelectionDidChange: notifications.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜