Re: Questions about NSPopupButtonCell and NSBrowser
Re: Questions about NSPopupButtonCell and NSBrowser
- Subject: Re: Questions about NSPopupButtonCell and NSBrowser
- From: "Frank D. Engel, Jr." <email@hidden>
- Date: Wed, 03 Jun 2015 20:20:18 -0400
After all of this, I finally at least partially solved this one.
I added a line of code to run each time that method is called.
It wasn't being called most of the time. I found where I was calling
this and changed the code a bit to use a binding created by code, and
now it is almost working.
The images are in the second column of the browser (these columns are
actually the same A and B as the NSPopupButtonCell question I still am
trying to figure out - the first column shows A, and second column shows
the B's for that A).
If I arrange for one of them to start changing while I have a particular
A selected, it works as long as I keep that A selected. When I switch to
a different A then switch back while it should still be changing, it is
"frozen" - the image appears from wherever it was when I switched away,
and my setImage method is not being called. When I select a B within
that A, it starts being called again.
I am wondering if the browser is actually caching an image of the cells
in the second column when I switch away, then just displaying that
without actually recreating the cells in the second column until it
needs one of them for something? That might explain the behavior I am
seeing, and may be a sensible optimization in most cases, but in this
instance it is not very helpful for my particular application.
On 6/3/2015 19:52, Frank D. Engel, Jr. wrote:
I based my code on one of Apple's examples and had tried using
NSBrowserCell but was not able to get that working; I assume there is
some reason why Apple chose to use NSTextFieldCell in their example
and I followed suit.
Currently, I have this coded - I had tried several variations to force
the redraw and landed here but it still is not working consistently.
- (void)setImage:(NSImage *)newImage
{
//[newImage retain];
//[img release];
img = newImage;
[[self controlView] setNeedsDisplay:YES];
}
On 6/3/2015 19:39, Graham Cox wrote:
On 4 Jun 2015, at 7:29 am, Frank D. Engel, Jr. <email@hidden>
wrote:
Now what I am hoping is the simpler one:
I have a custom subclass of NSTextFieldCell which I am using to show
an icon in an NSBrowser. The icon image is being generated
dynamically by a method in my subclass and I want it to change more
or less in "real time" as a bound value changes. I have that almost
working, but the one problem is that it doesn't refresh when I need
it to.
Is there some way I can "force" a browser cell to redraw its image,
short of redrawing the entire browser or window? The text isn't
changing, just the icon, but I'd settle for redrawing the cell...
I've tried a number of things to get this working and it seems I
keep coming up short.
NSBrowser normally uses NSBrowserCell to draw its content. That class
has a -setImage: method which presumably knows how to mark the
correct part of its host view as needing display.
If you have to use a different cell class, then you’ll need to figure
out how to do the same. The cell is part of a 1-column NSMatrix which
has methods to return the rect occupied by a given row, so given that
you can call -setNeedsDisplayInRect: on the matrix itself. Useful
methods there are -[NSMatrix getRow:column:ofCell:] and -[NSMatrix
cellFrameAtRow:column:];
hth,
—Graham
_______________________________________________
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