如果我将这些行放在xxxAppDelegate.m文件中,它工作正常。但我需要在另一个模块(如main.m等)下使用它。编译器生成一个错误,指出该窗口未定义。 “窗口”,在xxxAppDelegate modues定义,你怎么引用它在另一个模块xxxAppDelegate.m在运行时在objective-c中添加按钮控件Cocoa
旁边NSView *superview = [window contentView];
NSButton *button = [ [ NSButton alloc ] initWithFrame: NSMakeRect(10.0, 10.0, 200.0, 100.0) ];
[ button setBezelStyle:NSRoundedBezelStyle];
[ button setTitle: @"Click" ];
[superview addSubview:button];
[button setTarget:self];
[ button setAction:@selector(doSomething:)];
谢谢!那样做了。虽然我意识到创建一个类的实例的一般问题......但我可以弄清楚确切的语法......好的工作! – user523234 2011-05-07 01:36:04