views:

13

answers:

1

Hello,

I decided to use an alert sheet with 2 buttons. When the user clicks the continue button a sheet made from a window should come down. The sheet comes down and the parent window closes along with the other sheet. The code I'm using is:

- (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(int     *)contextInfo
{
if (returnCode == kOkayButtonCode) {
    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
    NSString *status = [defaults objectForKey:@"userStatus"];

    if (status == @"NO") {
        [NSApp beginSheet:theSheet modalForWindow:window
            modalDelegate:self didEndSelector:NULL contextInfo:nil];
    }

    if (status == @"YES") {

    }
}
if (returnCode == kCancelButtonCode) {
    [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.45];
   }
}

Can anyone see a problem with this?

Thanks for any help

A: 

Found a workaround with a timer.

- (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(int         *)contextInfo
{
if (returnCode == kOkayButtonCode) {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString *status = [defaults objectForKey:@"userStatus"];

if (status == @"NO") {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0.45];
        NSTimer *theTimer = [[NSTimer alloc] initWithFireDate:date
                                                  interval:1
                                                    target:self
                                                  selector:@selector(startSheet:)
                                                  userInfo:nil repeats:NO];

        NSRunLoop *runner = [NSRunLoop currentRunLoop];
        [runner addTimer:theTimer forMode: NSDefaultRunLoopMode];
        [timer2 release];   
}

if (status == @"YES") {

}
}
if (returnCode == kCancelButtonCode) {
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.45];
   }
}


-  (void)startSheet:(NSTimer *)theTimer {
[NSApp beginSheet:theSheet modalForWindow:window
    modalDelegate:self didEndSelector:NULL contextInfo:nil];
}
happyCoding25