Re: Image in NSOutlineView
Re: Image in NSOutlineView
- Subject: Re: Image in NSOutlineView
- From: chaitanya pandit <email@hidden>
- Date: Tue, 2 Sep 2008 19:57:08 +0530
If you want to preserve the state for other cells then you can
maintain an instance variable (flag) in the ImageAndTextCell, so in
outlineViewSelectionDidChange, you simply get the cell for the
selected row and set it's
flag to YES, and in willDisplayCell you simply check that flag of the
given cell and set it's image accordingly
On 02-Sep-08, at 5:16 PM, email@hidden wrote:
Thanks Chaitanya,
I tried it out and working well but, having one problem, when I
clicking
one image changes the image to checkbox_click.gif and when I selecting
another image it is changed and also all other images are set into
checkbox_non.gif, which is not I need. Actually I want to change the
image when it is clicked and also preserve all other images as it is.
For that in willDisplayCell method I did like:
id cell = [[[OutlineView tableColumns] objectAtIndex:0]
dataCellForRow:[OutlineView selectedRow]];
if ([[tableColumn identifier] isEqualToString:@"firstColumn"])
{
if ([OutlineView itemAtRow:[OutlineView selectedRow]] == item)
{
if([ [[cell image]name] isEqualToString:@"checkbox_none"])
[(ImageAndTextCell *)cell
setImage:[NSImageimageNamed:@"checkbox_click.gif"]];
else
[(ImageAndTextCell *)cell setImage:[NSImage
imageNamed:@"checkbox_none.gif"]];
}
else
{
if([ [[cell image]name] isEqualToString:@"checkbox_click"])
[(ImageAndTextCell *)cell setImage:[NSImage
imageNamed:@"checkbox_click.gif"]];
else
(ImageAndTextCell *)cell setImage:[NSImage
imageNamed:@"checkbox_none.gif"]];
}
}
But it is not working up to my expectation.When i clicking the image
sometimes it changes and otherwise not. How can I make it accurate ?
As per the initial description of your problem, you just want to
change the image of the cell when it is clicked(selected) right?
If thats the case then you don't have to deal with checking the image
name etc. neither u have to do the setImage stuff in
outlineviewSelectionDidChange
What you do is in the willdisplayCell method, check if the cell being
displayed is for the selectd (clicked) row, if it is then change it's
image else set the default image
here is the code snippet for the same
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:
(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
if ([[tableColumn identifier] isEqualToString:@"firstColumn"])
{
// If the cell being displayed is for the selected row, change it's
image
if ([outlineView itemAtRow:[outlineView selectedRow]] == item)
[(ImageAndTextCell *)cell setImage:[NSImage
imageNamed:"checkbox_click.gif"]];
// Else display the default image
else
[(ImageAndTextCell *)cell setImage:[NSImage
imageNamed:@"checkbox_none.gif"]];
}
}
hth,
Chaitanya
On 01-Sep-08, at 5:59 PM, email@hidden wrote:
Thanks for your consideration,
In the willDisplayCell i did like:
if ([[tableColumn identifier] isEqualToString:@"firstColumn"])
{
NSString *imageName = nil;
NSImage *image = nil;
imageName = @"checkbox_none.gif";
image = [NSImage imageNamed:imageName];
ImageAndTextCell *imageAndTextCell = (ImageAndTextCell *)cell;
[imageAndTextCell setImage:image];
}
And in the outlineViewSelectionDidChange method Idid like:
id cell = [[[OutlineView tableColumns] objectAtIndex:0]
dataCellForRow:[OutlineView selectedRow]];
NSString *imageName = nil;
NSImage *image = nil;
id Name = [[cell image]name];
if([Name isEqualToString:@"checkbox_none.gif"])
{
imageName = @"checkbox_click.gif";
image = [NSImage imageNamed:imageName];
ImageAndTextCell *imageAndTextCell = (ImageAndTextCell
*)cell;
[imageAndTextCell setImage:image];
}
else
{ imageName = @"checkbox_none.gif";
image = [NSImage imageNamed:imageName];
ImageAndTextCell *imageAndTextCell = (ImageAndTextCell
*)cell;
[imageAndTextCell setImage:image];
}
[OutlineView reloadData];
But it only work for root nodes.When I clicking on child nodes,image
is
changing in root node. Where I got wrong ? How can I implement it in
willDisplay method ?
Thanks in advance.
The right place to change the image of the cell would be in the
outlineView's delegate method:
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:
(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
try [[cell image] name] to get the name of the image
-chaitanya
On 29-Aug-08, at 5:41 PM, email@hidden wrote:
Hi all,
I'm trying to develop an application that uses an OutlineView in
which it
displays items like a disclosure triangle, then one checkbox,
then a
text
field int the same column. For that I gone through the
DragNDropOutlineview example provided with Xcode. Then I copied
the
ImageAndTextCell class and uses two images, one is checked and
other
is
unchecked. Now the application works with showing one image.I
want to
change the image when clicking on it. How can I do that ?. In
which
method
I want to write the code ?
In outlineViewSelectionDidChange method I wrote some code but it
faild.
When I taking the information about image like:
id cell = [[[OutlineView tableColumns] objectAtIndex:0]
dataCellForRow:[OutlineView selectedRow]];
id info = [cell image];
NSLog(@" %@",info);
It writes the log like:cell NSImage 0x17d8a0 Name=checkbox_click
Size={13,
13} Reps=(
NSBitmapImageRep 0x17e0c0 Size={13, 13}
ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=32 Pixels=13x13
Alpha=NO Planar=NO Format=1 CGImage=0x17ded0.
How can i get the Image name only ?
Thanks in advance
_______________________________________________
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
_______________________________________________
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