Saturday, August 4, 2012

Implementation of a tree structure in OSX -Step 2 (NSOutlineView, NSTreeController)

To continue you need to add an outline view to the main window.

View -> Utilities ->Show Utilities 
This will show you utilities tool bar.

Type outline in the search field.
Drag and drop outline view on the main window. After that you can adjust the sizes and change the number of columns of the outline view.

















After that the application window will look  like this.




In the project navigator bar you can see AppDelegate.h , AppDelegate.m and MainMenu.xlb files.

In AppDelegate.h file you need to add the following code.

 #import <Cocoa/Cocoa.h>  
 @interface AppDelegate : NSObject <NSApplicationDelegate>{  
   IBOutlet NSTreeController *treeController;  
   IBOutlet NSOutlineView *outlineView;  
 }  
 @property (assign) IBOutlet NSWindow *window;  
 - (void)awakeFromNib;  
 @end  

Next we have to create the bindings between the relevant classes.
We need to add a TreeController class object to the project.

In order to add that, you have to search in the objects library (like you did for outline view).
Drag and drop it to the Placeholder bar in the MainMenu.xlb view.

Above the Tree Controller object, you can find the object that was automatically created for AppDelegate class. We will need the them sooner....



Since  this article is going to be too long, we will continue in the next article....

No comments:

Post a Comment