Re: Problem in displaying image in NSTableView
Re: Problem in displaying image in NSTableView
- Subject: Re: Problem in displaying image in NSTableView
- From: Steve Christensen <email@hidden>
- Date: Mon, 20 Apr 2009 17:01:05 -0700
On Apr 18, 2009, at 7:54 PM, cocoa learner wrote:
Hello All,
In my NSTableView I am using NSImageCell as one column to display
images.
And I have implemented my datastore method like this -
- (id) tableView: (NSTableView *)aTableView
objectValueForTableColumn: (NSTableColumn *)aTableColumn
row: (NSInteger)rowIndex
{
/* code to display other column data
.....
*/
//Code to display image
if (coloumnIndex == 2)
{
NSImage *tmpImage = [[tableData objectAtIndex: rowIndex] personPhoto];
NSLog(@"TableController::dataSourceSecondAPI : [ Debug ] Coloumn
Index = 2,
so returning the image");
return tmpImage;
}
}
And my persons init method looks like this -
- (id) init
{
[super init];
Probably safer to use "self = [super init];" here. For most classes
self won't change, but it has been brought up on-list before that
there are some exceptions where [super init] can give you a
completely different instance.
personName = @"New name";
personAddr = @"New addrress";
personPhoto = [[NSImage alloc] initWithContentsOfFile:
@"/Volumes/Working/cocoa/Play-NSTableView/Linea.jpg"];
if (personPhoto == nil)
{
You need a call to [self dealloc] here, otherwise you leak an
instance of the class if you can't load the image.
return nil;
}
return self;
}
After running my application the image looks very small like an icon.
Can any one tell me how to display a bigger image in NSTableView?
The image is scaled to fit the table's row height, rather than having
the row height adjusted to fit a particular image. If the row height
isn't currently large enough, you can either change it in IB or in
code. And for 10.4 and later, you can have your table's delegate
implement -tableView:heightOfRow: to change the height on a row-by-
row basis.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden