gpt4 book ai didi

macos - 在方法中间显示模态窗口

转载 作者:行者123 更新时间:2023-12-03 17:55:33 25 4
gpt4 key购买 nike

所以我有一个程序,在发生 try/catch block 后,我需要出现一个模式窗口,以便用户可以做出特定的选择,然后我希望程序继续。我不知道如何进行这项工作,并且不断收到这些异常。

*** Assertion failure in -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:], /SourceCache/AppKit/AppKit-1187.34/AppKit.subproj/NSApplication.m:3920

Exception detected while handling key input.

Modal session requires modal window

我已经将我的模态表配置为以两种不同的方式显示,第一种方式是通过按下按钮,第二种方式是在我的 try catch block 之后。当我通过直接链接到配置游戏的按钮使其出现时,它工作正常,但是当我通过另一种方法中的 try catch block 执行此操作时,它会抛出上面的所有异常。

//Method that opens the modal sheet
- (IBAction)configureGame:(id)sender
{
//Calls a webview for the user to go to a specific location
NSString *FGstarter = @"http://www.google.com";
NSURL *FGplayerUrl = [NSURL URLWithString:FGstarter];
[webView setMainFrameURL:[FGplayerUrl absoluteString]];

//Opens the Modal Sheet
[NSApp beginSheet:configureSheet modalForWindow:mainWindow
modalDelegate:self didEndSelector:NULL contextInfo:nil];

}

//Select Method to a Select button which also closes the Sheet
- (IBAction)select:(id)sender{
//sets a NSString Instance Var to the Current URL of the webView
currentPage = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"]);

//Closes the sheet
[NSApp endSheet:configureSheet];
}


-(NSMutableArray *)loadPlayer:(NSString *)name{
@try {
// Code here might cause exception that gets caught in the catch
}
@catch (NSException *exception) {
//When I call this function I get all the exceptions listed in the top of the post
[self configureGame:nil];
//Ideally here what would happen here is the modal sheet would pop up the user would hit the select button that calls the select method then the program continues running.
}
NSString *page = currentPage;
//...Continue Using this method
}

最佳答案

请不要这样做。来自苹果文档...

Important In many environments, use of exceptions is fairly commonplace. For example, you might throw an exception to signal that a routine could not execute normally—such as when a file is missing or data could not be parsed correctly. Exceptions are resource-intensive in Objective-C. You should not use exceptions for general flow-control, or simply to signify errors. Instead you should use the return value of a method or function to indicate that an error has occurred, and provide information about the problem in an error object. For more information, see Error Handling Programming Guide.

另请参阅此问题的最佳答案:
When porting Java code to ObjC, how best to represent checked exceptions?

关于macos - 在方法中间显示模态窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14297126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com