我是 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/