Re: Why is a button in a window not redrawn when I change its state?
Re: Why is a button in a window not redrawn when I change its state?
- Subject: Re: Why is a button in a window not redrawn when I change its state?
- From: Ulf Dunkel <email@hidden>
- Date: Tue, 05 Jul 2011 12:10:10 +0200
- Organization: invers Software & DSD.net
Hi Jens.
This is the method in my AppDelegate.m which should update the button:
- (void)updateKillHelpdButton
{
[killHelpdButton setEnabled:[self checkHelpd]];
[killHelpdButton setNeedsDisplay:YES];
}
Can someone please tell me what else I should do to force the redraw?
That should work; in fact, you don’t even need the -setNeedsDisplay: call.
- Is this method being called when you expect? Set a breakpoint in it,
or add an NSLog call.
- Is killHelpdButton set to the right value, e.g. non-nil?
- Are you calling this on a background thread? In general you should
only call AppKit from the main thread.
The method was properly called, but I found out that it was a timing
issue. When I called [self checkHelpd] directly after another action,
the method -checkHelpd checked data in the system which hadn't been
refreshed yet (kind of race condition with the file system, I guess).
Switching app processes to and fro did of course give enough time to
have the data updated so -applicationWillBecomeActive: could catch the
changed situation. :-S
Now I set up another approach which uses
[self performSelector:@selector(updateKillHelpdButton) withObject:nil
afterDelay:1.0];
when I can be sure that the app actively changed the state of the
killHelpdButton object.
But because my app also should check whether other apps launched helpd,
I also added an NSTimer which checks every 5 seconds if the state should
be changed.
PS: I am quite sure that there is no official API for what I am doing
here, so I fear there's no other nice way of checking if helpd has been
launched. I could get rid of this all if I'd "cover" the relevant button
in a sheet which isn't visible all the time, but I'd like to keep it in
the main window of this tiny tool.
---Ulf Dunkel
_______________________________________________
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