I might be asking very simple question, but i am not able to get how to get rid of this, the requirement is,
- Table should display image and some text next to that. To do that, i have added two columns in the table
- 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.
- 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 retu开发者_运维问答rn 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,
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.
精彩评论