【发布时间】:2013-10-06 05:41:31
【问题描述】:
我有一个应用程序,当在单独的窗口中单击或关闭复选框时,应该打开和关闭一个窗口。我可以打开它,但不能关闭它。我在 windowControllerObject 中定义了一个 NSWindow 并尝试关闭 NSWindow。相关代码为:
buttonController.h
@interface buttonController : NSWindowController
{
NSButton *showAnswerBox;
infoWindowController *answerWindowController;
}
- (IBAction)showAnswer:(id)sender;
@end
buttonController.m
- (IBAction) showAnswer:(id) sender
{
if ([sender state] == NSOnState) {
if (!answerWindowController) {
answerWindowController = [[infoWindowController alloc] init];
}
[answerWindowController showWindow:self];
}
else {
[answerWindowController hideWindow];
}
}
infoWindowController.h:
@interface infoWindowController : NSWindowController {
IBOutlet NSWindow * infoWindow;
}
- (id) init;
- (NSWindow *) window;
- (void) hideWindow;
- (void) tsSetTitle: (NSString *) displayName;
@end
在 infoWindowController.m 中:
- (NSWindow *) window
{
return infoWindow;
}
- (void) hideWindow
{
[[self window] close];
}
窗口打开,但不会关闭。我尝试了几种变体,包括 infoWindowController 上的 orderOut。我确定我错过了一些愚蠢的东西 - 它是什么?
在 IB 中,我什至可以打开窗口的唯一方法是如果选中“启动时打开”,我是否应该能够以编程方式打开它们?
【问题讨论】:
-
做过调试吗?方法叫什么?变量有效吗?
-
您是否有意用自己的实现覆盖窗口属性? hideWindow 方法中的 [infoWindow close] 会发生什么
-
已修改您的代码。请验证
-
Wain:是的,我添加了 NSLog 消息来验证调用了哪些方法。为了简洁起见,我删除了它们。
-
沃伦:不,我没有。我会检查的。
标签: objective-c macos cocoa nswindow