0

我决定使用带有 2 个按钮的警报表。当用户点击继续按钮时,一个由窗口制成的工作表应该下来。工作表下来,父窗口与另一张工作表一起关闭。我正在使用的代码是:

- (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];
   }
}

任何人都可以看到这个问题吗?

4

1 回答 1

1

找到了一个计时器的解决方法。

- (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];
}
于 2010-08-26T23:24:16.973 回答