Hi, Can you help me to fix this problem. I am customizing my table view to show various images in the background of the cells accordingly as
Selected : Font Changed to While Colour, Background image, Highlighted.png Deselected/Normal: Font -> Black colour, Bg Image: Default.png I tried to override - (void)drawInteriorWithFrame:(NSRect)theCellFrame inView:(NSView*)theControlView of NSCell to change the Font Color and BgImage according to the state as I mentioned earlier. Result: Once the application launched it is ok. Once I select col1 and select col2, my Col1 still shows the Highlighted image, infact it is deselected and supposed to show the Default Image. This because my Default image is a transparent image. Even after overlapping Default.png on Highlighted.png it is showing the same Highlighted.png. I guess what I need to do is to remove the image from the Cell before redrawing it. How to do I really don't know. Kindly look into this and help me in this regards. //// CustomTableCell @interface CustomTableCell : NSCell { } @end #import "CustomTableCell.h" @implementation CustomTableCell - (void)drawInteriorWithFrame:(NSRect)theCellFrame inView:(NSView*)theControlView { NSLog(@"CustomTableCell drawInteriorWithFrame"); NSImage *bgImage = [NSImage imageNamed:@"DefaultCell"]; // Make attributes for our strings NSMutableParagraphStyle * aParagraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease]; [aParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; [aParagraphStyle setAlignment:NSCenterTextAlignment]; // Title attributes: system font, 14pt, black, truncate tail NSMutableDictionary * aTitleAttributes = [[[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSColor blackColor],NSForegroundColorAttributeName, [NSFont systemFontOfSize:21.0],NSFontAttributeName, aParagraphStyle, NSParagraphStyleAttributeName, nil] autorelease]; // Make a Title string NSString * aTitle = [self stringValue]; NSLog(@"CellFrame:[%f %f] [%f %f]", theCellFrame.origin.x, theCellFrame. origin.y, theCellFrame.size.width, theCellFrame.size.height); NSRect anIconBox = theCellFrame; NSRect aTitleBox = NSMakeRect(theCellFrame.origin.x, theCellFrame.origin.y + theCellFrame.size.height/2-10, theCellFrame.size.width, theCellFrame.size.height); if( [self isHighlighted]) { // if the cell is highlighted, draw the text white [aTitleAttributes setValue:[NSColor whiteColor] forKey: NSForegroundColorAttributeName]; bgImage = [NSImage imageNamed:@"FocusedCell"]; } else { // if the cell is not highlighted, draw the title black and the subtile gray [aTitleAttributes setValue:[NSColor orangeColor] forKey: NSForegroundColorAttributeName]; } // Draw the icon [bgImage drawInRect:anIconBox fromRect:NSZeroRect operation: NSCompositePlusLighter fraction:1.0]; // Draw the text [aTitle drawInRect:aTitleBox withAttributes:aTitleAttributes]; } @end //// CustomTableView @interface CustomTableView : NSTableView { } @end #import "CustomTableView.h" @implementation CustomTableView - (void)awakeFromNib { NSLog(@"CustomTableView awakeFromNib"); [[self enclosingScrollView] setDrawsBackground:NO]; } - (void)drawBackgroundInClipRect:(NSRect)clipRect { NSLog(@"CustomTableView drawBackgroundInClipRect"); } #pragma mark - #pragma mark Selection Highlighting - (id)_highlightColorForCell:(NSCell *)cell { // we need to override this to return nil // or we'll see the default selection rectangle when the app is running // in any OS before leopard // you can also return a color if you simply want to change the table's default selection color return nil; } @end Thanks in advance Regards symadept _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com