Re: NSOutlineView
Re: NSOutlineView
- Subject: Re: NSOutlineView
- From: Ken Thomases <email@hidden>
- Date: Sat, 06 Sep 2014 12:42:26 -0500
On Sep 6, 2014, at 11:58 AM, Charles Jenkins <email@hidden> wrote:
> I’m returning the correct string that should appear at every node of the tree, but it’s not being used. Each node in the tree is a text view cell. If I leave IB’s default title of “Text View Cell,” that’s what appears on every node of the tree. If I delete that title, then the tree items are completely blank.
> What I need to know is this: If we assume that the function shown here—
>
> func outlineView(
> _outlineView: NSOutlineView!,
> objectValueForTableColumn tableColumn: NSTableColumn!,
> byItem item: AnyObject!
> ) -> AnyObject!
> {
> let node = getDocumentNodeFrom( item )
> let result = node.title
> return result
> }
>
>
> —returns a proper String value which came from the right element in the tree, how can I get my outline view’s text view cell to display it?
The outline view takes the value returned by your data source method and calls -setObjectValue: on the table cell view, if it responds to that. The cell view could be an NSControl such as NSTextField and that would work directly. However, the cell view is often an NSTableCellView. NSTableCellView does respond to -setObjectValue:, and so it receives the string you're returning. However, it doesn't do anything further with it.
One approach would be to subclass NSTableCellView to forward the object value on to the subviews.
It's often easier, though, to use bindings. You can bind the "value" binding of the text field inside your cell view to the cell view, with the model key path "objectValue".
Depending on your model, you may actually find it's better to have your data source return a "compound" model object and then bind the text field to just a specific property of that model object. So, your data source method could return the "node" and the text field could bind to objectValue.title. This approach allows you to add another view (say, an image view) and bind it to a different property of the object that's represented by the row. It also allows the text field to be editable and directly modify the model object by setting its title property (if that's something you want to allow).
Regards,
Ken
_______________________________________________
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
References: | |
| >NSOutlineView (From: Charles Jenkins <email@hidden>) |