• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem with updating NSProgressIndicator
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with updating NSProgressIndicator


  • Subject: Re: Problem with updating NSProgressIndicator
  • From: Andrew Merenbach <email@hidden>
  • Date: Tue, 20 May 2008 19:10:52 -0700

Hi, there,

I apologize for not being able to offer an "Ah-ha!!!" sort of solution immediately, and also for this very long e-mail. I don't know if my suggestions will help, but they may at least lead to cleaner code, and may perhaps solve your problems. If I may...

First, you may wish to rename your class to "VOMainController" or some such -- use a two-letter prefix (one that Apple doesn't use -- and "V" and "O" appear to be your initials), as directed by Apple (as far as I know) to prevent naming collisions, and give it a descriptive name that represents what it is -- "Wnd" seems to be to represent "window," but your class is neither an NSWindowController nor a subclass of NSWindow/NSPanel, and "controller" is a generic class name suffix for such a -- well, for such a controller (hence the convention).

Secondly, instead of using a static xxx = 0 declaration, I'd use an instance variable, and give it a name that will be clear what it represents, then initialize it in your -init method. Also, name it "steps" (or something like that). Also, *you haven't specified what xxx is*!!! I don't know what it defaults to -- but "static xxx = 0" doesn't explicitly make it into an int, a double, or a char -- it may (or may not be) compiler specific. Thus do give it a type.

Thirdly, by making giving the onTimer local variable the name "timer", you have just created a conflict with your instance variable "timer". So I'd rename the *local* one to "aTimer".

Additionally (and this might, or might not, help with your crash), you might want to retain your timer, in case it ever gets removed from the runloop but you wish to keep a reference to it. (Not sure why you'd do that, but it's good form to retain any ivars that are a subclass of NSObject, unless you're using Garbage Collection under Leopard.)

Also: you call [progress setHidden:NO] every time that the timer fires. This may prove inefficient later on, so I'd simply leave it unhidden.

My version of your code follows. Note that it was typed in Mail.app, so there may be an error or two. It should be fairly good to go, though. If you still have the freezing problem, try creating a *new* project under Xcode 2.5, if you haven't already, instead of importing your old one. That might do the trick, if some build settings got corrupted.

// === BEGIN INTERFACE CODE ===

@interface VOMainController : NSObject {
unsigned int steps; // on Leopard you can use "NSUInteger" instead of "unsigned int"
NSTimer *timer;
IBOutlet NSProgressIndicator *progress;
}


// I include these prototypes to show that we've overridden them
- (id)init;
- (void)dealloc;
- (void)awakeFromNib

// now for your own method:
- (void)onTimer:(NSTImer *)aTimer;


@end

// === END INTERFACE CODE ===



// === BEGIN IMPLEMENTATION CODE ===

@implementation VOMainController

- (id)init {
	self = [super init];
	if (self) {
		steps = 0;
	}
	return self;
}

- (void)dealloc {
// there have been debates on this mailing list as to the usefulness of
// nullifying instance variables (in this case your timer variable); I do it
// since I *feel* it to be good form, even if it appears to be a matter of taste


	[timer invalidate];	// very important
	[timer release];	// since we retained earlier
	timer = nil;		//

	[super dealloc];
}

- (void)awakeFromNib
{
	timer = [[NSTimer scheduledTimerWithTimeInterval:0.1
			target:self
			selector:@selector(onTimer:)
			userInfo:nil
			repeats:YES]
		retain];

	//[progress setHidden:YES];
}

- (void)onTimer:(NSTimer *)aTimer
{
	steps = (steps + 1) % 100;
	[progress setDoubleValue:steps];
	//[progress setHidden:NO];
}

@end

// === END IMPLEMENTATION CODE ===


Cheers, Andrew

On May 20, 2008, at 2:52 PM, Vitaly Ovchinnikov wrote:

It is working fine for me using Mac OS X 10.5 and Mac OS X 10.4 when
compiled with Xcode 2.5 against the 10.4u SDK (not tried any other
version of Xcode or SDK).

just installed XCode 2.5 and tried the demo project - result is the same, progress freezes. I have a slow computer, maybe the reason is here. it is G4 1.4GHz with 1 Gb RAM... _______________________________________________

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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: Problem with updating NSProgressIndicator
      • From: "Vitaly Ovchinnikov" <email@hidden>
    • Re: Problem with updating NSProgressIndicator
      • From: "Vitaly Ovchinnikov" <email@hidden>
References: 
 >Problem with updating NSProgressIndicator (From: "Vitaly Ovchinnikov" <email@hidden>)
 >Re: Problem with updating NSProgressIndicator (From: "Shawn Erickson" <email@hidden>)
 >Re: Problem with updating NSProgressIndicator (From: "Vitaly Ovchinnikov" <email@hidden>)
 >Re: Problem with updating NSProgressIndicator (From: "Shawn Erickson" <email@hidden>)
 >Re: Problem with updating NSProgressIndicator (From: "Vitaly Ovchinnikov" <email@hidden>)

  • Prev by Date: Re: Newbie question about Database
  • Next by Date: Re: Newbie question about Database
  • Previous by thread: Re: Problem with updating NSProgressIndicator
  • Next by thread: Re: Problem with updating NSProgressIndicator
  • Index(es):
    • Date
    • Thread