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

发布于 2024-09-16 19:21:57 字数 726 浏览 4 评论 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];
   }
}

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

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

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文