PDA

View Full Version : Quit Error (Have To Quite Twice To Terminate)




Darkroom
Nov 6, 2007, 12:38 AM
hi there...

i'm having a problem with my quit function... my app will only quit if i quite twice that is, i have to press Apple+Q two times for the app to terminate.

it may or may not have to do with my timer... i'm not sure... but something very strange is happening to the object as the "quitApplication" action will be added twice, no matter how many times i rewrite and set up the object. i've included an image to show you what i mean:

http://img.photobucket.com/albums/v365/geoff_mattie/Picture2.png

here's the code for the Fade Controller:

FadeController.h

#import <Cocoa/Cocoa.h>

@interface FadeController : NSObject {
IBOutlet NSWindow *mainWindow;
NSTimer *timer;
}

- (IBAction)quitApplication:(id)sender;

@end


FadeController.m

#import "FadeController.h"

@implementation FadeController

- (void)awakeFromNib {
[mainWindow setDelegate:self];
[mainWindow setAlphaValue:0.01];
timer = [[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(fadeIN:) userInfo:nil repeats:YES] retain];
}

- (void)fadeIN:(NSTimer *)theTimer {
if ([mainWindow alphaValue] > 0.0) {
[mainWindow setAlphaValue:[mainWindow alphaValue] + 0.1];
}
else
{
[timer invalidate];
[timer release];
timer = nil;
}
}

- (IBAction)quitApplication:(id)sender {
[mainWindow setAlphaValue:1.0];
timer = [[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(fadeOUT:) userInfo:nil repeats:YES] retain];
}

- (void)fadeOUT:(NSTimer *)theTimer
{
if ([mainWindow alphaValue] > 0.0) {
[mainWindow setAlphaValue:[mainWindow alphaValue] - 0.1];
}
else
{
[timer invalidate];
[timer release];
timer = nil;
[NSApp terminate:nil];
}
}


@end



Darkroom
Nov 6, 2007, 02:46 AM
ok so i fixed it... works fine now... it was a problem with my timer loop and not a bug with xc/ib3... i changed apart of the code to this to make the loop work:


- (void)awakeFromNib {
[mainWindow setDelegate:self];
[mainWindow setAlphaValue:0.0];
timer = [[NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(fadeIN:) userInfo:nil repeats:YES] retain];
}

- (void)fadeIN:(NSTimer *)theTimer
{
if ([mainWindow alphaValue] < 1.0) {
[mainWindow setAlphaValue:[mainWindow alphaValue] + 0.1];
}
else
{
[timer invalidate];
[timer release];
timer = nil;
}
}


however, it still strange why my Fade Controller is showing 2 quitApplication actions... if i try to remove one from the list by clicking on the "x", they both get disconnected... perhaps this is a bug in the software?

Gelfin
Nov 6, 2007, 10:54 AM
Don't know about the twin quit actions, but it looks like you might have some interesting results there of the "dueling timers" variety if somebody were to try quitting the application while it's still fading in. Maybe you want to check for and kill any existing timer before setting a new one in the quit action.

There seem to be some other more minor issues associated with quitting while a fade is in progress (in or out). Might want to temporarily set your timer interval higher so you can experiment with the scenario more easily and fix what breaks.

kainjow
Nov 6, 2007, 11:12 PM
however, it still strange why my Fade Controller is showing 2 quitApplication actions... if i try to remove one from the list by clicking on the "x", they both get disconnected... perhaps this is a bug in the software?

Did you try a simple relaunching of IB?

satyam90
Nov 7, 2007, 12:00 AM
How did u associate - (IBAction)quitApplication:(id)sender; to menu item? I mean from where you are calling the above method.