プログラムでウィンドウを開閉しようとしています。これが私の試みです。開いていますが、閉じていません。私は非常に多くの方法を試しましたがNSWindow
、他の部分で機能させるために何かをしなければならないと思います.
AppDelegate.h
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#import <AVFoundation/AVFoundation.h>
@class AVPlayer;
@interface AppDelegate : NSObject <NSApplicationDelegate> {
IBOutlet WebView *news;
IBOutlet NSButton *play;
IBOutlet NSButton *options;
IBOutlet NSButton *realmlist;
IBOutlet NSTextField *version;
AVPlayer *audioPlayer;
}
@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, retain) IBOutlet WebView *news;
@property (nonatomic, retain) IBOutlet NSTextField *version;
@property (nonatomic, retain) AVPlayer *audioPlayer;
-(IBAction)play:(id)sender;
-(IBAction)changeRealmlist:(id)sender;
-(IBAction)close:(id)sender;
-(IBAction)removeCache:(id)sender;
-(IBAction)sOptions:(id)sender;
@end
AppDelegate.m
-(IBAction)sOptions:(id)sender{
NSRect frame = NSMakeRect(670, 400, 451, 351);
NSUInteger styleMask = NSBorderlessWindowMask;
NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:styleMask];
NSWindow * optionsWindow = [[NSWindow alloc] initWithContentRect:rect styleMask:styleMask backing: NSBackingStoreBuffered defer:false];
[optionsWindow setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"opcionesbackground.gif"]]];
[optionsWindow makeKeyAndOrderFront: optionsWindow];
[optionsWindow setMovable:YES];
NSRect deleteCache = NSMakeRect(225, 200, 89, 36);
NSButton *button = [[NSButton alloc] initWithFrame:deleteCache];
[button setButtonType:NSMomentaryPushInButton];
//[button setImage:[NSImage imageNamed:@"rest_acepton.gif"]];
[button setTitle:@"Eliminar cache"];
[[button cell] setBackgroundColor:[NSColor redColor]];
[button setAction:@selector(removeCache:)];
[[optionsWindow contentView] addSubview:button];
[button setNeedsDisplay:YES];
NSRect accept = NSMakeRect(350, 20, 89, 36);
NSButton *aceptar = [[NSButton alloc] initWithFrame:accept];
[aceptar setButtonType:NSMomentaryPushInButton];
[aceptar setImage:[NSImage imageNamed:@"rest_acepton.gif"]];
[aceptar setBordered:NO];
[aceptar setTarget:optionsWindow];
[aceptar setAction:@selector(closeOptions:)];
[[optionsWindow contentView] addSubview:aceptar];
[aceptar setNeedsDisplay:YES];
}
-(void)closeOptions:(id)sender{
[optionsWindow orderOut:nil];
}