如何在Cocoa Mac中以编程方式关闭窗口? [英] How to close a window programmatically in Cocoa Mac?

查看:659
本文介绍了如何在Cocoa Mac中以编程方式关闭窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以可编程方式关闭可可mac中的窗口?我已经打开了第二个窗口/ xib从第一个窗口/ xib使用按钮单击。我需要在打开或点击按钮时以编程方式关闭第一个窗口/ xib。我该怎么办?

How can I programmatically close a window in cocoa mac ? I have opened a second window/xib from the first window/xib using button click. I need to close the first window/xib programmatically on opening or clicking the button. How can I do that?

推荐答案

Apple在网站加载。它不直接解决这个问题;下面的代码。

Apple has some useful sample code on Nib Loading. It doesn't directly address this question however; the following code does.

@interface CloseWindowAppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
    IBOutlet NSWindow * secondWindow;
    NSNib * secondNib;
}

@property (assign) IBOutlet NSWindow *window;

- (IBAction)openSecondWindow:(id)sender;

- (IBAction)closeSecondWindow:(id)sender;

@end







#import "CloseWindowAppDelegate.h"

@implementation CloseWindowAppDelegate

@synthesize window;

- (IBAction)openSecondWindow:(id)sender {
    secondNib = [[NSNib alloc] initWithNibNamed:@"SecondWindow" bundle:nil];
    [secondNib instantiateNibWithOwner:self topLevelObjects:nil];
    [secondWindow makeKeyAndOrderFront:nil];

}

- (IBAction)closeSecondWindow:(id)sender {
    [secondWindow close];
    [secondNib release];

}

@end

这篇关于如何在Cocoa Mac中以编程方式关闭窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆