0
votes

I might be asking very simple question, but i am not able to get how to get rid of this, the requirement is,

  1. Table should display image and some text next to that. To do that, i have added two columns in the table
  2. NSTableView should be transparent. To do that, i have made a CustomNSTableView class, inside override drawRect method for not to draw background, and tell cell not to drawBackground.
  3. Now the next hurdle is how to display an image, i had to override/handled following method

.

- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{

    NSImage *pCellImage = // Get a valid Image ;

    if(tableColumn == nil ) return nil;

    NSString *colName = [tableColumn identifier];
    if([colName isEqualToString:@"firstColumn"]){
        NSCell *pCell = [[NSCell alloc]initImageCell:pCellImage];
        return pCell;
    }else{
        NSCell *pCell = [[NSCell alloc]initTextCell:@"Some text"];
        return pCell;

    }
}

i added tableColumn == nil condition, as in the documentation its given, first time for each row , this will be called with tableCOlumn nil when i need to set a single column for entire row, but if i return its crashing with the comment BAD_ACCESS,

Now my question is how to handle nil condition, Also in this function after setting NSCell for both Column it goes to another delegate function

- (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

I believe, after setting dataSet properly i don't need to use this function,

With the following implementation its crashing, but i am not able to figure it out, what is wrong ,

i am setting proper dataSource and delegate,

1
very strange, if i comment setRowHeight then its not hitting EXE_BAD_ACCESS :(Amitg2k12

1 Answers

1
votes

Have you tried calling setBackgroundColor and passing the clear colour?

[myTableView setBackgroundColor:[[NSColor clearColor]];

If you use this method, remember to tell the surrounding NSScrollView not to draw it's background.

Alternatively, consider providing the table's background as a CALayer.

With regard to drawing the image and text in a single column, Apple's developer relations have published a custom NSCell, ImageAndTextCell. You can use this cell with NSTableView and NSOutlineView instances. This custom cell deals with drawing a image and text within a single column.