我的主窗口上有一个按钮,打开另一个窗口来收集用户输入。如果用户完成输入,窗口应该关闭。如果用户点击红色按钮,我需要显示警报并让窗口关闭。无论哪种情况,我都需要能够重新打开输入窗口。重新打开一个窗口并确定它是如何关闭的
我可以第一次打开窗口,但不能以编程方式关闭它,也不能重新打开它。我已阅读所有可找到的帖子,但没有找到可以应用于我的案例的帖子。我认为我的问题是一个出口,并委托。
该窗口的代表是Calibrate。
Calibrate.h
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
.
.
@interface Calibrate : NSWindowController
.
.
@end
Calibrate.m
#import "Calibrate.h"
Calibrate *calibrate;
- (IBAction)showCalibratePanel:(id)sender
{
[calibrate showWindow:self];
}
- (void)handleMaxAngleChange:(NSNotification *)notification
{
///// last step in info gathering
NSString *s = [[notification userInfo]objectForKey:@"myMaxAngleKey"];
gotResponse = NO;
[calibrate close]; //////////// does not close.
}
#import "Calibrate.h"
@interface Calibrate()
@end
@implementation Calibrate
.
.
- (id)init
{
self = [super initWithWindowNibName:@"Calibrate"];
return self;
}
- (void)windowDidLoad
{
[super windowDidLoad];
}
-(BOOL)windowShouldClose:(NSNotification *)note
{ //// fires when red button clicked but alert not shown.
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Incomplete calibration may cause ERC to not work correctly."];
[alert beginSheetModalForWindow:[NSApplication sharedApplication].mainWindow
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
return YES;
}
我认为你应该看看在一张纸而不是一个新窗口中呈现这种事情.. – Jef
@Jef - 我以前没有使用过纸张。有什么优势? – Mike
工作表只是一个连接到特定窗口的对话框,确保用户永远不会丢失对话框属于哪个窗口。将对话框连接到相关窗口的功能使用户能够充分利用OS X窗口分层模型,并鼓励无模式;用户可以在工作表打开时处理其他文档或其他应用程序。 (来自苹果文档https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Sheets/Concepts/AboutSheets.html#//apple_ref/doc/uid/20001043-BABFIBIA) – Jef