当我这样调用时,我试图以编程方式关闭模式警报表:
[alert beginSheetModalForWindow:contacts modalDelegate:self didEndSelector:@selector(myAlertEnded:code:context:) contextInfo:NULL];
Run Code Online (Sandbox Code Playgroud)
小智 8
我有同样的问题,我解决了这个问题.
1)启动工作表
[myAlertSheet beginSheetModalForWindow:self.view.window modalDelegate:self didEndSelector:@selector(showAlertDidEnd: returnCode: contextInfo:) contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)
2)以编程方式关闭模态表:
[NSApp endSheet:[myAlertSheet window]];
Run Code Online (Sandbox Code Playgroud)
myAlertSheet是一个NSAlert实例变量,用于跟踪屏幕上的模态表.然后,endSheet消息调用选择器:
- (void)showAlertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo
{...}
Run Code Online (Sandbox Code Playgroud)
我希望以上有用
您的控制器中将有一个这样的方法(modalDelegate):
- (IBAction) cancelClicked: (id) sender {
// Cancel the sheet and close.
[NSApp endSheet: [self window]];
}
Run Code Online (Sandbox Code Playgroud)
...将被连接到模式表中的“取消”按钮(或与此相关的“确定”按钮,但这可能会引发一些剥离处理)。
您还需要实现此功能didEndSelector才能实际删除工作表:
- (void) didEndSheet: (id) modalSheet returnCode: (NSInteger) returnCode contextInfo: (void*) contextInfo {
// Remove the sheet.
[modalSheet orderOut: nil];
}
Run Code Online (Sandbox Code Playgroud)
如果我没记错的话,我是从Apple文档中的示例中了解到的。
你会发现NSWindow一个名为 的方法attachedSheet。它生成对此窗口附加的工作表(如果有)的引用。工作表本身也只是一个NSWindow. 因此,您可能想尝试以下操作:
NSWindow *window = [NSApp mainWindow];
[[window attachedSheet] close];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5822 次 |
| 最近记录: |