Yes forgot to say that I've a data source for the outline view….

My OvItem.h class looks like this:

#import <Cocoa/Cocoa.h>

@interface OvItem : NSObject {
    
        NSString *title;
        NSMutableArray *children;
        BOOL isParent;
}

@property (nonatomic, readwrite, copy) NSString *title;
@property (retain, nonatomic, readwrite) NSMutableArray *children;
@property (nonatomic, assign) BOOL isParent;

// Initialization methods
- (id)initLeafWithTitle:(NSString *)theTitle;
- (id)initParentWithTitle:(NSString *)theTitle children:(NSMutableArray 
*)theChildren;

// Child access methods
- (NSInteger)numberOfChildren;
- (OvItem *)childAtIndex:(NSUInteger)theIndex;


and the implementation like this:

#import "OvItem.h"

@implementation OvItem

@synthesize title;
@synthesize children;
@synthesize isParent;


// Create the 'leaf' node (a node with no subnodes)
- (id)initLeafWithTitle:(NSString *)theTitle {
        
        if(self = [super init])
        {
                self.title = theTitle;
                self.children = nil;
                self.isParent = NO;
        }
        
        return self;
}

// Create a 'parent' node (a node with subnodes)

- (id)initParentWithTitle:(NSString *)theTitle children:(NSMutableArray 
*)theChildren {

        if(self = [super init])
        {
                
                self.title = theTitle;
                
                self.children = (theChildren != nil ? theChildren : 
[NSMutableArray array] );
                self.isParent = YES;
        }
        
        return self;
}


-(id)init
{
        [super init];
        
        children = [[NSMutableArray alloc] init];
        title = @"New_Item";
        
        return self;
        
}

// Getting the number of children a node has (needed for the sidebar datasource 
methods)
- (NSInteger)numberOfChildren {

        return [self.children count];
}

// Getting a given child (needed for the sidebar datasource methods)
- (OvItem *)childAtIndex:(NSUInteger)theIndex {
        
        return [self.children objectAtIndex:theIndex];
}


-(void) dealloc
{
        self.title = nil;
        self.children = nil;
        
        //[children release];
        //[title release];
        
        [super dealloc];
                
}



On Sep 2, 2011, at 2:35 PM, Michael Babin wrote:

> On Sep 2, 2011, at 7:15 AM, Gilles Celli wrote:
> 
>> I've setup a  Document based application with an NSOutlineView which 
>> displays Parent-Item along with its children…with XCode 4 on OS X Lion.
>> 
>> When launching the application, the outline view shows the Root title…only 
>> if I refresh the outline view the children are displayed too.
>> 
>> I've also tried to do a reloadData along with reloadItem:nil 
>> reloadChildren:YES for the OutlineView (in method windowDidLoad and tried 
>> also 
>> (void)applicationDidFinishLaunching: ) but this doesn't fix it…
>> 
>> However I've setup a NSButton to refresh the outlineView which then calls 
>> 'reloadData' and 'reloadItem:nil reloadChildren:YES' and then it works…
>> but this is of course not the solution I want…
> 
> This sounds like a problem of not having the data structure(s) 
> initialized/populated/connected when the outline view asks for the items to 
> be displayed, and then not notifying the outline view that it needs to reload 
> when the data is actually available.
> 
> I assume you're using a data source for your outline view? If so, try setting 
> a breakpoint on your -outlineView:numberOfChildrenOfItem: method to see when 
> the outline view is asking for the data, and then look at the source of that 
> data to figure out why it is not available at that point (and when it is 
> available).
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to