Re: NSButton alternate image problem - not redrawing
Re: NSButton alternate image problem - not redrawing
- Subject: Re: NSButton alternate image problem - not redrawing
- From: P Teeson <email@hidden>
- Date: Wed, 16 Jul 2008 17:32:35 -0400
On 16-Jul-08, at 1:03 PM, Gary L. Wade wrote:
<note top post moved to bottom>
Mac OS X Tiger 10.4.11, Xcode 2.5, G4 867mhz
I am making a Cocoa Application kids game using NSButtons.
They are of behaviour Toggle and of type Square Button and the icon
position is centred (i.e. no title) and each button has a unique tag
and is enabled.
The icon images are in the nib file and consist of
(a) a coloured blank square and
(b) a set of coloured squares with large letters in the centre.
In the nib all buttons have the blank icon image as both image and
alternate image. Connections are made in IB from each button to the
Controller IBAction method. Likewise connections are made from
the Controller IBOutlets to the respective buttons.
When the game begins I successfully retrieve all the icon images from
the bundle and keep them as instance variables in my Controller.
(e.g. IBOutlet NSButton * cell0; IBOutlet NSButton *cell1; etc)
The game is played by clicking on a button and a message is sent to
an IBAction method in the Controller. It replaces the alternate image
with one of the (b) icons and disables that button.
......
[sender setAlternateImage:theXiconImage];
[sender setEnabled:NO];
......
This all works exactly and desired.
There is another NSButton to trigger a New Game and it sends a
message to an IBAction method in the Controller that re-initialises
the buttons as follows:
......
[cell0 setAlternateImage:theBlankImage]; // send messages via
IBOutlet
[cell0 setEnabled:YES];
[cell1 setAlternateImage:theBlankImage];
[cell1 setEnabled:YES];
[cell2 setAlternateImage:theBlankImage];
[cell2 setEnabled:YES];
etc....
......
(Of course the Model is also reinitialised)
My Problem is this
The View gets redrawn OK.
But now when clicking on a button there is no guarantee that the
alternate images will appear.
Sometimes they do; sometimes they don't - just displaying the
blank icon.
And yet the same action method is being called as in the first play
of the game.
Why do you think this is not redrawing correctly after the
reinitialisation?
TIA for your suggestions.
If I'm reading you right (the action of a button click causes that
same button to get a new alternate image),
I would say that you should set the alternate image before the user
clicks on the button.
Once a button is toggled, the current alternate image (or image,
depending on state) is drawn
Thanks for your thought but I don't see why that is so. Initially the
button has blank icons for both images.
User clicks on button, action method is called, in that method a
different alternate image is set,
the button is disabled, the action method is exited, and
button is redrawn showing the new image.
This all works perfectly for the first play of the game; i.e. when
the View is loaded from the .nib.
So dynamically changing the alternate image in the action method
actually works.
However when that game is over the user clicks on the "New Game"
button which invokes an
action method to restore the game to it's inital values, including
the images and enablement of the buttons.
(see the above code snippet)
Now when the user plays the second, and subsequent, games it's a crap
shoot as to whether or not the
alternate image actually displays or whether it's just the blank icon
that shows up. I don't understand
why it wouldn't work as before. Maybe there is some hidden caching
going on.
respect...
Peter
_______________________________________________
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