Question

UI Requirement is, 1 -- Need to show a two column table, first col should display an image and 2nd col will have some text with it, 2 -- It should be transparent so it should display the NSView background,

My code is written as below,

I subclass NSTableView overriding following methods

-(void)awakeFromNib
{

    [[self enclosingScrollView] setDrawsBackground: NO];
    [[self enclosingScrollView] setBorderType:NSNoBorder];

}

- (BOOL)isOpaque {

    return NO;
} 
- (void)drawRect:(NSRect)drawRect
{
    [super drawRect: drawRect];
}

In my view creating table instance as below

@interface MyView : CommUICustomView {
    CustomTableView *myTableView;
}

// IMplementation

- (void)InitContactTable 
{

    NSRect          scrollFrame = [self bounds];
    NSScrollView*   scrollView  = [[[NSScrollView alloc] initWithFrame:scrollFrame] autorelease];

    [scrollView setBorderType:NSNoBorder];
    [scrollView setHasVerticalScroller:YES];
    [scrollView setHasHorizontalScroller:NO];
    [scrollView setAutohidesScrollers:YES];
    [scrollView setDrawsBackground: NO];

    NSRect          clipViewBounds  = [[scrollView contentView] bounds];
    pOnLineCTView       = [[[CommUITableView alloc] initWithFrame:clipViewBounds] autorelease];

    //[pOnLineCTView setBackGroundImageByName:@"largegears.png"];


    NSTableColumn*  firstColumn     = [[[NSTableColumn alloc] initWithIdentifier:@"firstColumn"] autorelease];
    [[firstColumn dataCell] setDrawsBackground:NO];

    [myTableView  addTableColumn:firstColumn];

    NSTableColumn*  secondColumn        = [[[NSTableColumn alloc] initWithIdentifier:@"secondColumn"] autorelease];
    [[secondColumn dataCell] setDrawsBackground:NO];

    [myTableView  addTableColumn:secondColumn];

    [myTableView setDataSource:self];
    [scrollView setDocumentView:pOnLineCTView];

    [scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];

    [self addSubview:scrollView];

    [self setAutoresizesSubviews:YES];


}

The output of above code is , Table with White background, even if i set NoofRow are 0, i.e. White background is getting drawn, Next i tried, implementing Background in TableView by overriding drawRect method of CustomTableView, it helped me, and output is Background image, to achieve transparent and show Parent view background, but painted with the white color, it seems, its getting white color drawn because of Column or cell, i tried to tell Cell of Column not to draw Backgorund but it didn't work, Any other method any guys can suggest me.

Was it helpful?

Solution

Its working, i was overriding drawBackgroundInClipRect also, but after commented this method, i could see the expected output,

Now i can see, transparent background with table cell data being display on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top