objective-c - 线程1 :EXC_BAd_InSTRUCTION(code =EXC_1386_INVOP,子代码)

标签 objective-c macos cocoa uialertsheet nsrunalertpanel

我是 Cocoa 的新手,xcode。我正在做示例项目“如何显示 AlertPanel 和警报表。我遇到这样的错误”thread1:EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP,subcode=...)。Here我提到了我收到错误的代码行。请帮助我。

Alert.beginSheetModalForWindow(window,completionhandler:{(code:NSMOdalResponse)-> void in.

最佳答案

NSAlert beginSheetModalForWindow 用于 Mac OS 开发。

正如您提到 iPhone 作为此问题的标签,我假设您正在开发 iOS 应用程序。对于 iOS 开发,请使用 UIAlertController。这是示例代码:

UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];

   UIAlertAction* yesButton = [UIAlertAction
                        actionWithTitle:@"Yes"
                        style:UIAlertActionStyleDefault
                        handler:^(UIAlertAction * action) {
                            //Handel yes button action here
                        }];
   UIAlertAction* noButton = [UIAlertAction
                            actionWithTitle:@"No"
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction * action) {
                               //Handel no button action here
                           }];

   [alert addAction:yesButton];
   [alert addAction:noButton];

   [self presentViewController:alert animated:YES completion:nil];

更多详情,请参阅Apple iOS Documentation

希望这有帮助。

关于objective-c - 线程1 :EXC_BAd_InSTRUCTION(code =EXC_1386_INVOP,子代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37617525/

相关文章:

ios - iOS中的跳过/忽略方法

macos - 在 Mac 上安装 npm 时遇到问题

bash - 在 MacOS 中,当电池电量低于阈值时播放警告的脚本

objective-c - Mac 将音频和视频文件合并在一起

ios - 方法在第二次通过 : SVPullToRefresh 时不起作用

ios - 如何使用 core_bluetooth 获取公共(public)蓝牙设备地址

Swift 2,协议(protocol)扩展和 respondsToSelector

cocoa - 有什么工具可以加速 Cocoa 开发吗?

ios - 如何在模型对象中存储许多图像? Objective-C

macos - 如何在 Mac OS X 上设置 Docker Tomcat 容器