我有一个应用程序,当按下按钮时它应该显示一个模式窗口。我对此有一些疑问,但我将把它缩小到让我头疼的地方。
我想补充一点,当应用于这种特殊情况时,我已经在做类似的事情了。我已经做的是模态显示一个 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 文件,该文件具有一个类似于 NSPanel 的 HUD 窗口(它在 IB 中的命名方式)。我创建了一个监听按钮(testButton)的windowcotroller。这是代码:
@interface BrowserWindowController : NSWindowController {
}
-(IBAction) testButton:(id) sender;
@end
我将 xib 文件的文件所有者设置为 BrowserWindowController 类,并将按钮与 testbutton 链接。
单击按钮时返回 appDelegate 我想以模态方式显示此面板。这是代码:
- (IBAction) respondToBrowseAction:(id) sender {
browsePanel = [[BrowserWindowController alloc] initWithWindowNibName:@"BroserWindow"];
}
我在 API 中看不到任何功能,例如 NSOpenPanel 以模态方式显示此窗口。
感谢任何可能回答的人。