我有一些代码试图用一种方法显示我的 prefwindow,但我删掉了其余部分并留下了窗口 init 和其他方法。那么如何跨方法访问对象呢?
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
@interface hello : NSObject <NSApplicationDelegate> {
NSWindow *prefwindow;
}
@property (assign) IBOutlet NSWindow *window;
-(void)openPrefs;
@end
@implementation hello;
@synthesize window;
int main (int argc, const char * argv[]) {
hello *self = [[hello alloc] init];
[NSAutoreleasePool new];
[NSApplication sharedApplication];
id prefwindow = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 350, 150)
styleMask:(NSTitledWindowMask | NSClosableWindowMask) backing:NSBackingStoreBuffered defer:NO]
autorelease];
[prefwindow center];
[prefwindow setTitle:appName];
[prefwindow setDelegate:self];
[self openPrefs];
[NSApp setDelegate:self];
[NSApp run];
return 0;
}
-(void)openPrefs {
[NSApp activateIgnoringOtherApps: YES];
[prefwindow makeKeyAndOrderFront: self];
}
@end