【问题标题】:Alert message not disappearing when the user click "ok" button用户单击“确定”按钮时警报消息不会消失
【发布时间】:2015-12-12 06:41:53
【问题描述】:

我正在使用警报表来显示警报消息。我将警报表放在主线程中,并且我使用了更多这样的警报表,但是在运行应用程序时会出现警报消息。

但有时当用户单击警报消息中的确定按钮时。警报消息没有消失,我无能为力。我唯一能做的就是杀死应用程序并重新启动它。

我检查了日志文件以发现问题。但我无法从日志文件中获取问题,而且一切正常,日志文件中没有崩溃。我检查了更多参考资料,但找不到问题出在哪里。这是示例代码。

 dispatch_async(dispatch_get_main_queue(), ^{

                                            NSAlert *alertView2 = [NSAlert alertWithMessageText:@"Server error occured. please check the internet connectivity" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@""];

                                            [[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];

                                            int response;

                                            [alertView2 beginSheetModalForWindow:self.window

                                                                     modalDelegate:self

                                                                    didEndSelector:@selector(alertDidEndDoNothing:returnCode:contextInfo:)

                                                                       contextInfo:&response];

 });

问题是由于线程。这意味着同时调用了两个方法,或者问题在警报表中。

【问题讨论】:

    标签: objective-c multithreading cocoa nsalert


    【解决方案1】:

    我认为您使用“get_main”块在主线程上完成了所有工作,因此当您确实不需要对主线程执行繁重的任务时使用dispatch_async(dispatch_get_main_queue),它会冻结您的 UI 和应用程序。

    【讨论】:

      猜你喜欢
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 2011-03-15
      • 2011-10-03
      • 1970-01-01
      • 2021-12-15
      • 2021-08-06
      相关资源
      最近更新 更多