Mac Quit Error (Have To Quite Twice To Terminate)

Darkroom

Guest
Original poster
Dec 15, 2006
2,448
0
Montréal, Canada
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:



here's the code for the Fade Controller:

FadeController.h
Code:
#import <Cocoa/Cocoa.h>

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

- (IBAction)quitApplication:(id)sender;

@end
FadeController.m
Code:
#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

Guest
Original poster
Dec 15, 2006
2,448
0
Montréal, Canada
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:

Code:
- (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

macrumors 68020
Sep 18, 2001
2,166
4
Denver, CO
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

Moderator emeritus
Jun 15, 2000
7,958
5
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.