Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 从警报中调用工作表会导致奇怪的窗口问题_Cocoa_Nswindow_Nsalert - Fatal编程技术网

Cocoa 从警报中调用工作表会导致奇怪的窗口问题

Cocoa 从警报中调用工作表会导致奇怪的窗口问题,cocoa,nswindow,nsalert,Cocoa,Nswindow,Nsalert,我决定使用带有两个按钮的警告表。当用户单击“继续”按钮时,从窗口制作的一张纸应该会下来。工作表将下降,父窗口将与其他工作表一起关闭。我使用的代码是: - (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(int *)contextInfo { if (returnCode == kOkayButtonCode) { NSUserDefaults* defaults = [NSUse

我决定使用带有两个按钮的警告表。当用户单击“继续”按钮时,从窗口制作的一张纸应该会下来。工作表将下降,父窗口将与其他工作表一起关闭。我使用的代码是:

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

有人看到这有问题吗?

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

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