Node hierarchy with subclasses
Node hierarchy with subclasses
- Subject: Node hierarchy with subclasses
- From: BareFeet <email@hidden>
- Date: Fri, 29 Jan 2010 18:55:22 +1100
Hi All,
Summary:
I have an NSTreeController driven hierarchy of "Nodes" in my window's left pane. I'd like to subclass Node into a few subclasses. Each subclass in the model shows its own tab view item(s) in the view (right half of the document window). The tab view item contains UI elements (eg text fields), each of which is bound (via bindings) to a property of that subclass.
The problem is that when a subclass A is selected, the UI elements bound to subclass B no longer have valid bindings so generate an error. How can I solve this?
Example:
As described before, I have my Node tree in the left pane and different tab view items showing on the right according to what Node is selected.
I'd like to subclass Node according to type. If this was iTunes, for example, I might have subclasses like MoviesNode, PlayListNode etc as subclasses of the general Node class used in the tree. MoviesNode would have methods particular to showing the list of Movies which are not relevant for all Nodes, etc. For instance, I might have a "width" method that returns the width of a movie as an integer. I could display this value by creating a text field bound (ie via bindings) to the NSTreeController's selection.width model key path. If I show this text field in the Movies tab view item it works fine as long as I have selected a MoviesNode, but if I select a different subclass of Node (eg playlist) or no Node is selected (such as when the nib awakens), there is no width property, so it generates an error, similar to:
HIToolbox: ignoring exception '[<Node 0x1001db8e0> addObserver:<NSKeyValueObservance 0x1004aeea0> forKeyPath:@"width" options:0x100 context:0x0] was sent to an object that is not KVC-compliant for the "width" property.' that raised inside Carbon event dispatch
I have tried to code the removal of the Movies tab containing the text field bound to the width property, but the error occurs before awakeFromNib is called and in the init method it's too early (since there's nothing yet loaded to remove).
It seems to me to be a common UI layout to have a Node tree on the left and various UI elements on the right appearing according to what Node is selected. But how can I do this using bindings?
Thanks,
Tom
BareFeet
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden