Re: NSTableView, NSArrayController, and ImageAndTextCell
Re: NSTableView, NSArrayController, and ImageAndTextCell
- Subject: Re: NSTableView, NSArrayController, and ImageAndTextCell
- From: Vincent Coetzee <email@hidden>
- Date: Sat, 8 Nov 2003 09:11:41 +0200
Hi Kurt
Below is a class called IconCell that I use in conjunction with tables
and outline views to do this, if I understand what you are looking for.
Let me know if it is of use. The IconCell class is attached with the
set up code.
This is the code to set it up, I usually put it in the awakeFromNib
message
theCell = [[IconCell alloc] init];
[theCell setFont: [[[theOutliner tableColumnWithIdentifier: @"0"]
dataCell] font]];
[[theOutliner tableColumnWithIdentifier: @"0"] setDataCell: theCell];
I then set my controller up as a delegate of the table or outliner and
define the following
- (void)outlineView:(NSOutlineView *)outlineView
willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn
item:(id)item
{
SourceRecord* record;
IconCell* localCell;
record = (SourceRecord*)item;
localCell = (IconCell*)cell;
[localCell setTitle: [record name] image: [record image]];
}
//
// IconCell.h
// Cambridge
//
// Created by Vincent Coetzee on Tue Nov 04 2003.
//
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
@interface IconCell : NSCell
{
NSImage* theImage;
NSString* theTitle;
NSMutableDictionary* theAttributes;
}
- (void) setTitle: (NSString*) aString image: (NSImage*) image;
- (void) setFont: (NSFont*) font;
- (void) drawInteriorWithFrame: (NSRect) rect inView: (NSView*) view;
@end
//
// IconCell.m
// Cambridge
//
// Created by Vincent Coetzee on Tue Nov 04 2003.
//
#import "IconCell.h"
@implementation IconCell
- (void) setTitle: (NSString*) aString image: (NSImage*) image
{
[aString retain];
[theTitle release];
theTitle = aString;
[image retain];
[theImage release];
theImage = image;
}
- (void) setFont: (NSFont*) font
{
[super setFont: font];
[theAttributes release];
theAttributes = [[[NSMutableDictionary alloc] init] retain];
[theAttributes setObject: font forKey: NSFontAttributeName];
}
- (void) drawInteriorWithFrame: (NSRect) rect inView: (NSView*) view
{
NSPoint point;
NSSize size;
NSPoint origin;
origin = rect.origin;
if (theImage != nil)
{
size = [theImage size];
point.x = origin.x+3;
point.y = origin.y + size.height;
[theImage compositeToPoint: point operation: NSCompositeSourceOver];
point.x = point.x + size.width + 3;
}
else
{
point.x = origin.x+3;
}
point.y = origin.y;
[[[NSAttributedString alloc] initWithString: theTitle attributes:
theAttributes] drawAtPoint: point];
}
@end
On Nov 08, 2003, at 07:11, Kurt Marek wrote:
>
I'm trying to get an icon next to the text in my tableView. I've
>
downloaded Apple's ImageAndTextCell and I'm trying to get it to work
>
with a tableView that is bound to an NSArrayController. I haven't been
>
able to get it to work yet; has anyone else had success with this?
>
>
Here's the strategy I'm trying. The NSArrayController controls an array
>
of custom classes consisting of two instance variables: objectTitle and
>
objectITCell (an instance of the ImageAndTextCell). I bound the column
>
in my tableView to NSArrayController selection.objectITCell. I can set
>
the image in the objectITCell instance programatically and I can get
>
the table to add records and edit the cell, but I can't get the cell to
>
display the image and the text. Although I assumed that setting up the
>
binding this way would tell the column to expect this specialized cell
>
type, I also tried to set it manually:
>
>
NSTableColumn *tableColumn = nil;
>
ImageAndTextCell *imageAndTextCell = nil;
>
tableColumn = [sourceTableView tableColumnWithIdentifier: @"Source"];
>
imageAndTextCell = [[[ImageAndTextCell alloc] init] autorelease];
>
[imageAndTextCell setEditable: YES];
>
[tableColumn setDataCell:imageAndTextCell];
>
>
>
This doesn't seem to help either. Any help?
>
>
Kurt
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.