3
votes

i've got a Delegate class for a Source List. But i don't know what type the return variable of outlineView:objectValueForTableColumn:byItem: should be.

At the Moment my code looks like this, all the structure things work but there is no text shown:

@interface DataSource : NSObject<NSOutlineViewDelegate,NSOutlineViewDataSource>

@end

And the .m

@implementation DataSource
// Data Source methods

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {

    return (item == nil) ? 1 : [item numberOfChildren];
}


- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
    return (item == nil) ? YES : ([item numberOfChildren] != -1);
}


- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {

    return (item == nil) ? [FileSystemItem rootItem] : [(FileSystemItem *)item childAtIndex:index];
}

//-(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
    return @"Some String";
}


@end

I have made a example app to show the difference. Image is here

1
if you set a breakpoint on your return line, does it ever hit in the Debugger? - Michael Dautermann
No it never gets to this point. - thomasguenzel
Looks to me like you will need to edit your question to show more code, because if that breakpoint isn't even hitting, then you probably did not implement the data source's other required methods properly. As for your original question, you should be able to return a NSString type and it should display just fine (once you actually do hit that breakpoint). - Michael Dautermann
now the code includes the 2 files from the delegate object - thomasguenzel

1 Answers

7
votes

I suppose you have view-based NSTableView. In you delegate you should implement method - (id)outlineView:(NSOutlineView *)ov viewForTableColumn:(NSTableColumn *)tableColumn. It may looks like this:

- (id)outlineView:(NSOutlineView *)ov viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item{
    if ([[item representedObject] parent] == nil) {
        return [ov makeViewWithIdentifier:@"HeaderCell" owner:self];
    }else{
        return [ov makeViewWithIdentifier:@"DataCell" owner:self];
    }
}

HeaderCell and DataCell are default identifiers of the Table Cell Views.