I am writing a small application tentatively called "CocoaMix", the purpose of which is to test out code that I have written for accessing the accessibility hierarchy on various UIs. Essentially what I am trying to accomplish is an NSOutlineView
on the left and an "example" view on the right of a test user interface.
So far, for the data source implementation I have:
@interface CMTopLevelCategory : NSObject
@property (readonly) NSString *name;
@property (readonly) NSArray *examples;
- (id)initWithName:(NSString *)name examples:(NSArray *)examples;
@end
@interface CMExample : NSObject
@property (readonly) NSString *name;
- (id)initWithName:(NSString *)name;
@end
@interface CMSideOutlineViewDataSource : NSObject <NSOutlineViewDataSource>
@end
//...
#define CMNameColumnIdentifier @"name"
#define CMCountColumnIdentifier @"count"
@interface CMSideOutlineViewDataSource ()
@property NSArray *topLevelCategories;
@end
@implementation CMSideOutlineViewDataSource
- (id)init {
self = [super init];
if (self) {
CMExample *largeTableExample = [[CMExample alloc] initWithName:@"Large Table"];
CMTopLevelCategory *tablesCategory = [[CMTopLevelCategory alloc] initWithName:@"Tables" examples:@[ largeTableExample ]];
_topLevelCategories = @[ tablesCategory ];
}
return self;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
if (item) {
if ([item isKindOfClass:CMTopLevelCategory.class]) {
CMTopLevelCategory *topLevelCategory = item;
return [topLevelCategory.examples objectAtIndex:index];
}
} else {
return [self.topLevelCategories objectAtIndex:index];
}
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
return [item isKindOfClass:CMTopLevelCategory.class];
}
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
if (item) {
if ([item isKindOfClass:CMTopLevelCategory.class]) {
CMTopLevelCategory *topLevelCategory = item;
return [topLevelCategory.examples count];
}
} else {
return [self.topLevelCategories count];
}
return 0;
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
if ([item isKindOfClass:CMTopLevelCategory.class]) {
CMTopLevelCategory *topLevelCategory = item;
if ([tableColumn.identifier isEqualToString:CMNameColumnIdentifier]) {
return topLevelCategory.name;
} else if ([tableColumn.identifier isEqualToString:CMCountColumnIdentifier]) {
return [NSNumber numberWithUnsignedInteger:[topLevelCategory.examples count]];
}
} else if ([item isKindOfClass:CMExample.class]) {
CMExample *example = item;
if ([tableColumn.identifier isEqualToString:CMNameColumnIdentifier]) {
return example.name;
}
}
return @"default value";
}
@end
To explain this, the top level items are supposed to be categories of examples like "Tables", and then for each category there are going to be some example UIs (e.g. "Large Table" in the "Tables" category of examples).
When I build and run, breakpoints that I have set in outlineView:objectValueForTableColumn:byItem:
are triggered, but the text in the NSOutlineView
is still the placeholder "Table Cell View" text:
What am I doing wrong?