Maurizio
Maurizio

Reputation: 577

How do I add a NSOutlineViewDataSource to my NSOutlineView?

I am writing a System Preference pane for Mac OS X in Objective-C. The panel includes a NSOutlineView bound to a properly configured NSTreeController. I also added a delegate class for my OutlineView in which I defined my own outlineView:viewForTableColumn:item: method.

enter image description here

When I add new objects to the Tree Controller everything works fine, but now I want to enable persistence for expanded items. To do so I need to implement outlineView:itemForPersistentObject: and outlineView:persistentObjectForItem: in a data source for the OutlineView, otherwise I get the error:

*** NSOutlineView data source ((null)) does not implement outlineView:persistentObjectForItem:

How do I do that given my current setup?

Upvotes: 1

Views: 337

Answers (2)

Willeke
Willeke

Reputation: 15632

The delegate and data source can be the same object. Implement the methods in OutlineViewDelegate and connect the data source the the same object as the delegate.

Upvotes: 1

larod
larod

Reputation: 435

Did you declare that class (the class that is providing the data) as the NSOutlineViewDataSource? Something along these lines:

@interface YourClass : NSObject <NSApplicationDelegate, NSWindowDelegate, NSUserNotificationCenterDelegate, NSTableViewDataSource, NSTableViewDelegate, NSOutlineViewDataSource, NSOpenSavePanelDelegate>

*The other declarations are just examples, in this particular case the YourClass inherits from several other ones.

After you declare this you can either use bindings or you can manually connect the data source to your outlineView.

Upvotes: 1

Related Questions