Re: Progress bar
Re: Progress bar
- Subject: Re: Progress bar
- From: Shawn Erickson <email@hidden>
- Date: Thu, 10 Nov 2005 15:06:53 -0800
On Nov 10, 2005, at 2:13 PM, Andrea Salomoni wrote:
Hi,
yes is a cocoa application template.
And no... I think isn't enough to setstingvalue (i.e for a status
message.
Which class is awakeFromNib in? What is it a subclass of?
If it is a view class of some type then you shouldn't be doing what
you are doing in awakeFromNib. Also if it is your applications
delegate then you should likely do what you are doing in
applicationDidFinishLaunching:.
I wrote this:
-(void)awakeFromNib
{
[myStatusField setStringValue:@"Setting up database"];
[myStatusField display];
You should seldom need to call display directly yourself but instead
send the view object a setNeedsDisplay:YES message. Also sending
setStringValue will trigger the object to mark itself as need to be
redisplayed (in other words sending it setNeedsDisplay: isn't needed).
With that said in this case you are doing a long run body of work on
the main thread (awakeFromNib is called by the main thread) and
attempting to display information (status) while doing that. The
issue you are hitting is that normal view drawing will not take place
until the end of the current event cycle, at that point the main
thread will get the chance to ask views that need to redraw
themselves to do so. You long run body of work however is not
allowing the event loop to proceed to that point (you don't return
out of awakeFromNib).
For this scenario your options are to explicitly trigger the view
element to draw itself (likely best to use displayIfNeeded) or rework
things such that your long run body of work takes place in a
secondary thread. Using a secondary thread for this work will allow
the main thread to do its normal event loop which includes asking
dirty views to redraw themselves.
If you do want to use a secondary thread then to update status use
something like the following...
[myStatusField performSelectorOnMainThread:@selector(setStringValue:)
withObject:@"Setting up database"
waitUntilDone:NO];
... setup database ...
[myStatusField performSelectorOnMainThread:@selector(setStringValue:)
withObject:@"Quering database....."
waitUntilDone:NO];
...
Personally I would use a secondary thread for this.
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden