Hello to the list !

As the title say, I could use home help.
I'm still on the learning path.

This code is attempt of implementing a Leopard style source list using a NSOutlineView. Code provided below works but as seen from the console output of NSLog's it displays come cell's number of times which probably means that my implementation of some methods is fault in some part. Also execution is noticeable slow.

I would be grateful if someone could inspect this code and explain to me where are my mistakes and point out possible solutions which
would improve this code.

It would be very useful for my better understanding and future learning.

Also to mention that I have read Apple's documentation regarding the subject and have downloaded and examine a lot of examples of source list implementations but those examples were just too complicated to understand how to implement data source methods, and documentation
on the other hand is too general.

If someone wants to test this code in the Xcode just a remainder to connect IBOutlet, data source and delegate connections in Interface Builder.

And at the end there is a delegate method implementation but I comment it out because it is also fault. It makes things even worse.
Please review it too and explain to me what did I missed out.

Thanks for help !

----------------------------------------------------------------------------------------------------------------------------------------

#import <Cocoa/Cocoa.h>


@interface LSOutlineDataSource : NSObject
{
        IBOutlet NSOutlineView *lsOutlineView;
        
        NSMutableArray *sourceListLevelZero;
}

@property (assign) NSMutableArray *sourceListLevelZero;

@end

-------------------------------------------------------------------------------------------------------------------------------------------

#import "LSOutlineDataSource.h"


@implementation LSOutlineDataSource

@synthesize sourceListLevelZero;

- (id)init
{
        if (self = [super init])
        {
                sourceListLevelZero = [[NSMutableArray alloc] init];
                
NSMutableDictionary *showOne = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"NEWS AT 6", @"nameOfShow", [[NSMutableArray alloc] initWithObjects:@"MONDAY", @"TUESDAY", @"WEDNESDAY", @"THURSDAY", @"FRIDAY", @"SATURDAY", @"SUNDAY", nil], @"listOfShowsRundownLists", nil];
                [sourceListLevelZero addObject:showOne];
                [showOne release];
                
NSMutableDictionary *showTwo = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"NEWS AT 10", @"nameOfShow", [[NSMutableArray alloc] initWithObjects:@"MONDAY", @"TUESDAY", @"WEDNESDAY", @"THURSDAY", @"FRIDAY", @"SATURDAY", @"SUNDAY", nil], @"listOfShowsRundownLists", nil];
                [sourceListLevelZero addObject:showTwo];
                [showTwo release];
        }
        return self;
}

- (void)awakeFromNib
{
        [lsOutlineView expandItem:nil expandChildren:NO];
}

- (void)dealloc
{
        [sourceListLevelZero release];
        [super dealloc];
}

#pragma mark NSOutlineViewDataSource protocol methods

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
        if (item == nil)
        {
                item = sourceListLevelZero;
                
                NSLog(@"1 - item number of children is %i", [item count]);
                return [item count];
        }
        if ([item isKindOfClass:[NSDictionary class]])
        {
NSLog(@"1.1 - item number of children is %i", [[item objectForKey:@"listOfShowsRundownLists"] count]);
                return [[item objectForKey:@"listOfShowsRundownLists"] count];
        }
        NSLog(@"1.2 - item number of children is 0");
        return 0;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
        if (item == nil)
        {
                item = sourceListLevelZero;
                
NSLog(@"2 - item at index %i is %@", index, [item objectAtIndex:index]);
                return [item objectAtIndex:index];
        }
        if ([item isKindOfClass:[NSDictionary class]])
        {
NSLog(@"2.1 - item for key \"listOfShowsRundownLists\" at index %i is %@", index, [[item objectForKey:@"listOfShowsRundownLists"] objectAtIndex:index]); return [[item objectForKey:@"listOfShowsRundownLists"] objectAtIndex:index];
        }
        NSLog(@"2.2 - item is not valid");
        return nil;
}

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable: (id)item
{
if ([item isKindOfClass:[NSArray class]] || [item isKindOfClass: [NSDictionary class]])
        {
                if ([item count] > 0)
                {
                        NSLog(@"3 - item is expandable");
                        return YES;
                }
        }
        NSLog(@"3.1 - item is not expandable");
        return NO;
}

- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
        if ([item isKindOfClass:[NSDictionary class]])
        {
NSLog(@"4 - item for key \"nameOfShow\" is %@", [item objectForKey:@"nameOfShow"]);
                return [item objectForKey:@"nameOfShow"];
        }
        if ([item isKindOfClass:[NSString class]])
        {
                NSLog(@"4.1 - item is %@", item);
                return item;
        }
        NSLog(@"4.2 - item is not valid");
        return nil;
}

#pragma mark NSOutlineView delegate methods

//- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
//{
//      if ([item isKindOfClass:[NSDictionary class]])
//      {
//              if ([item objectForKey:@"nameOfShow"])
//              {
//                      NSLog(@"5 - item is group");
//                      return YES;
//              }
//      }
//      NSLog(@"5.1 - item is not group");
//      return NO;
//}

@end

------------------------------------------------------------------------------------------------------------------------------------------------------

Mario Kušnjer
mario.kusn...@sb.t-com.hr
+385957051982
mariokusn...@skype

_______________________________________________

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