Tom*_*mas 0 desktop objective-c titanium nsalert appcelerator
我目前正在通过实现一个我认为在 Titanium Appcelerator Desktop SDK 中缺少的功能来学习(通过实践)objective-c:一种使用自定义按钮文本进行模式对话框并可选择将其显示为“工作表”的方法。
一切都很花哨并且工作正常,但是,当将 NSAlert 显示为“表”时,我创建警报的方法会立即返回,这就是我想要防止的。
创建警报的方法返回一个 int (来自 NSAlert 的返回代码)。
里面的代码基本上可以归结为:
int returnCode = -1;
if (displayAsSheet) {
[alert beginSheetModalForWindow:nativeWindow modalDelegate:delegate didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
} else {
returnCode = [alert runModal];
}
return returnCode;
Run Code Online (Sandbox Code Playgroud)
modalDelegate 是一个实现所需功能的对象:
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
Run Code Online (Sandbox Code Playgroud)
现在它只执行 returnCode 的 NSLog。
所以我的问题是:
在“工作表”被解除之前,如何阻止我的方法返回?
或者我以错误的方式处理这个问题?
您必须在显示工作表后启动工作表的模式会话,并在关闭工作表后停止会话。
检查这个: https: //github.com/incbee/NSAlert-SynchronousSheet,我认为这会有帮助。