在IB中创建的NSWindow不会在应用程序中以模态方式显示

发布于 2024-09-29 14:58:39 字数 1521 浏览 4 评论 0原文

我有一个应用程序,当按下按钮时它应该显示一个模式窗口。我对此有一些疑问,但我会将其范围缩小到令我头疼的问题。

我想补充一点,我已经在做类似的事情,但应用于这种特殊情况时是行不通的。我已经做的是以模态方式显示 NSOpenPanel。这是它的代码。

此代码位于 appDelegate 内部。

-(IBAction) respondToPublishAction:(id) sender {
    NSArray *fileTypes = [NSArray arrayWithObjects:@"xml", @"txt", nil];

    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

    NSString *startingDir = [[NSUserDefaults standardUserDefaults] objectForKey:@"StartingDirectory"];

    if (!startingDir)
        startingDir = NSHomeDirectory();

//Setting the attributes
[oPanel setAllowsMultipleSelection:NO];
[oPanel setTitle:@"XML file for publishing services"];
[oPanel beginSheetForDirectory:startingDir file:nil types:fileTypes
                modalForWindow:[self window] modalDelegate:self
                didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
                   contextInfo:nil];
}

现在我想做的事情是行不通的,

我创建了一个 xib 文件,它有一个 HUD 窗口(它在 IB 中的命名方式),其作用类似于 NSPanel。我创建了一个监听按钮(testButton)的 windowcoroller。代码如下:

@interface BrowserWindowController : NSWindowController {
}
-(IBAction) testButton:(id) sender;
@end

我将 xib 文件的文件所有者设置为 BrowserWindowController 类,并将按钮与测试按钮链接起来。

回到 appDelegate 当单击按钮时我想以模式方式显示此面板。代码如下:

- (IBAction) respondToBrowseAction:(id) sender {
browsePanel = [[BrowserWindowController alloc] initWithWindowNibName:@"BroserWindow"];
}

我在 API 中没有看到任何像 NSOpenPanel 这样以模态方式显示此窗口的函数。

感谢任何可能回答的人。

I have an application that when pressing a button it should show a modal window. I have some questions about it but I'm going to narrow it to what it's giving me a headache.

I want to add that I'm already doing something alike that when applied to this particularly case won't work. What I already do is to show modally a NSOpenPanel. This is the code for it.

This code is inside the appDelegate.

-(IBAction) respondToPublishAction:(id) sender {
    NSArray *fileTypes = [NSArray arrayWithObjects:@"xml", @"txt", nil];

    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

    NSString *startingDir = [[NSUserDefaults standardUserDefaults] objectForKey:@"StartingDirectory"];

    if (!startingDir)
        startingDir = NSHomeDirectory();

//Setting the attributes
[oPanel setAllowsMultipleSelection:NO];
[oPanel setTitle:@"XML file for publishing services"];
[oPanel beginSheetForDirectory:startingDir file:nil types:fileTypes
                modalForWindow:[self window] modalDelegate:self
                didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
                   contextInfo:nil];
}

Now What I'm trying to do and that won't work

I created a xib file that has a HUD Window (how it's named in IB) that acts like a NSPanel. I created a windowcotroller that listen to a button (testButton). Here's the code:

@interface BrowserWindowController : NSWindowController {
}
-(IBAction) testButton:(id) sender;
@end

I set the file's owner of the xib file to be of the class BrowserWindowController and linked the button with the testbutton.

Back to the appDelegate when a button is clicked I want to show this Panel modally. Here's the code:

- (IBAction) respondToBrowseAction:(id) sender {
browsePanel = [[BrowserWindowController alloc] initWithWindowNibName:@"BroserWindow"];
}

I don't see any function in the API like NSOpenPanel to show this window modally.

Thx to anyone who might answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情未る 2024-10-06 14:58:39

没有用于模态运行的 NSWindow API 的原因是应用程序要进入模态模式。请参阅模态窗口工作原理和< a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Sheets/Sheets.html" rel="nofollow">表格简介。

The reason there is no NSWindow API for running modally is because it's the application that is going into a modal mode. See How Modal Windows Work and Introduction to Sheets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文