2

我正在尝试以编程方式打开和关闭一个窗口。这是我的尝试,我打开但没有关闭它。我已经尝试了很多方法,但我认为我必须对它做一些事情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];
}
4

1 回答 1

0

根据您的来源,“optionsWindow”是方法 sOptions 的 ivar。你怎么能在另一种方法中使用?你能发布正确的来源吗

于 2013-12-18T14:06:46.760 回答