【问题标题】:Call a sheet from within an alert causes weird window problems从警报中调用工作表会导致奇怪的窗口问题
【发布时间】:2010-08-26 21:34:36
【问题描述】:

我决定使用带有 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];
   }
}

谁能看出这个问题?

【问题讨论】:

    标签: cocoa nswindow nsalert


    【解决方案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];
    }
    

    【讨论】:

      猜你喜欢
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多