我的目标:当应用程序通过冗长的循环时,显示带有确定的NSProgressIndicator的自定义工作表.我希望工作表是应用程序模式,而不是文档模式.用户无法关闭模态表.他们必须等待应用程序完成循环处理.
问题:我无法将自定义工作表附加到窗口.它显示为缺少窗口标题栏的单独窗口(如表单所示).此外,当循环结束时,纸张不会释放(不会关闭).
我有两个单独的nib文件用于工作表和主应用程序窗口,还有两个控制器类用于每个窗口.
以下是相关信息:自定义工作表的控制器实现:
@implementation ProgressSheetController //subclass of NSPanel
-(void)showProgressSheet:(NSWindow *)window
{
//progressPanel is an IBOutlet to the NSPanel
if(!progressPanel)
[NSBundle loadNibNamed:@"ProgressPanel" owner:self];
[NSApp beginSheet: progressPanel
modalForWindow: window
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
//modalSession is an instance variable
modalSession = [NSApp beginModalSessionForWindow:progressPanel];
[NSApp runModalSession:modalSession];
}
-(void)removeProgressSheet
{
[NSApp endModalSession:modalSession];
[NSApp endSheet:progressPanel];
[progressPanel orderOut:nil];
}
//some other methods
@end
Run Code Online (Sandbox Code Playgroud)
主应用程序窗口的实现.testFiles方法是一个连接到按钮的IBAction.
@implementation MainWindowViewController //subclass of NSObject
-(IBAction)testFiles:(id)sender;
{
//filesToTest is a mutable array instance variable
int count = [filesToTest count];
float …Run Code Online (Sandbox Code Playgroud) 我试图在我的应用程序中显示自定义工作表,但我认为我做错了什么.虽然一切似乎都很好,但我有一个相当奇怪的副作用.(花了几个小时才算出来).事实证明,每当我在我的应用程序中显示一个工作表时,Application委托就会被设置为工作表的实例,因此我的Controller将被取消设置为委托导致各种问题.
我创建了一个名为FailureSheet.xib的NIB文件.我在IB中布置了我的接口,然后创建了一个名为'FailureSheet.m'的'NSWindowController'的子类,我将其设置为File的Owner.这是我的FailureSheet类:
#import "FailureSheet.h"
@implementation FailureSheet // extends NSWindowController
- (id)init
{
if (self = [super initWithWindowNibName:@"FailureSheet" owner:self])
{
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (IBAction)closeSheetTryAgain:(id)sender
{
[NSApp endSheet:[self window] returnCode:1];
[[self window] orderOut:nil];
}
- (IBAction)closeSheetCancel:(id)sender
{
[NSApp endSheet:[self window] returnCode:0];
[[self window] orderOut:nil];
}
- (IBAction)closeSheetCancelAll:(id)sender
{
[NSApp endSheet:[self window] returnCode:-1];
[[self window] orderOut:nil];
}
@end
Run Code Online (Sandbox Code Playgroud)
这里没有什么复杂的事情发生.现在这就是我在'Controller'类中显示FailureSheet的方法:
sheet = [[FailureSheet alloc] init];
[NSApp beginSheet:[sheet window]
modalForWindow:window
modalDelegate:self
didEndSelector:@selector(failureSheetDidEnd:etc:etc:)
contextInfo:nil]; …Run Code Online (Sandbox Code Playgroud) 默认情况下,Cocoa在应用于窗口时会向透明和半透明模态图纸添加背景模糊效果.我想禁用模糊效果.我该怎么做呢?
我创建了一个自定义工作表(NSWindow的子类,具有透明背景和一些控件).我可以使用标准beginSheet方法显示它,如下所示:
[NSApp beginSheet:myCustomSheet
modalForWindow:mainWindow
modalDelegate:self
didEndSelector:...];
Run Code Online (Sandbox Code Playgroud)
表单显示正常,但它背后的一切都很模糊.
注1:我正在为触摸屏/自助服务终端类型的应用程序编写完全自定义的用户界面,因此没有适用的常用Apple用户界面指南.
注2:我确实想看看表格下面的内容.正如SirRatty指出的那样,可以通过填充背景来阻挡模糊部分.在我的情况下,我希望通过背景显示,只是没有出现模糊.
Snow Leopard没有为旧的beginSheet引入一些替代方法:允许使用块来完成整理的方法吗?我不喜欢在另一个回调方法中使用它.
我有一个这样的窗口,有 3 个子视图,每个子视图都有按钮。单击那些 - 我需要显示工作表。


通过使用此代码,工作表位于窗口的中心。
- (IBAction)closeSubWindow:(id)sender{
[NSApp endSheet:self.subWindow];
[self.subWindow orderOut:nil];
}
- (IBAction)showSubWindow:(id)sender {
[NSApp beginSheet:self.subWindow
modalForWindow:self.window
modalDelegate:self
didEndSelector:nil
contextInfo:nil];
}
Run Code Online (Sandbox Code Playgroud)
是否有任何选项或方法可以在特定坐标处显示工作表?
编辑:
我目前的实现是通过使用NSPopover. 我可以让它NSPopover像工作表一样动画吗?
如何NSWindow从工具栏中显示a ,如下NSOpenPanel图所示?

我正在尝试创建一个自定义模式窗口,这是我到目前为止的代码:
NSWindowController *modalSheet = [[NSWindowController alloc]
initWithWindowNibName:@"MyCustomWindow" owner:self];
[NSApp beginSheet:[modalSheet window]
modalForWindow:[self windowForSheet]
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)
窗口弹出正常,但它不是模态的,例如,您仍然可以对请求来自的父窗口执行操作.从NSDocument对象调用此方法.
我试过阅读:使用自定义表格
但是我不确定myCustomSheet它是什么,因为它没有在任何地方声明.我假设它是一个NSWindow实例变量.
我只是无法理解为什么它不是模态的.任何帮助将非常感激.谢谢
cocoa ×7
cocoa-sheet ×7
objective-c ×5
macos ×3
nswindow ×3
delegates ×1
nsopenpanel ×1
transparency ×1