【发布时间】:2015-07-06 17:34:02
【问题描述】:
我已经能够以编程方式创建一个 NSPopupButton 并将其添加到我的窗口中,并且我可以通过相同的方法将项目添加到列表中,但我想弄清楚如何从另一个方法中将项目添加到它方法。
这是我目前的工作:
// in my .h file:
@interface AVRecorderDocument : NSDocument
{
@private
NSPopUpButton *button;
}
@property (assign) IBOutlet NSWindow *mainWindow;
// in my .m file:
@implementation AVRecorderDocument
@synthesize mainWindow;
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
NSView *superview = [mainWindow contentView];
NSRect frame = NSMakeRect(10,10,149,22);
NSPopUpButton *button = [[NSPopUpButton alloc] initWithFrame:frame];
[superview addSubview:button];
[button release];
}
- (void)refreshDevices
{
// I'd like to add items to my popupbutton here:
// [button addItemWithTitle: @"Item 1"];
}
@end
在 refreshDevices 中我没有收到编译器错误,只是没有任何内容添加到弹出按钮中。从 -(id)init 调用方法 refreshDevices。我还尝试将 windowControllerDidLoadNib 中的代码放在我的 init 部分的顶部,但它甚至不会在那里创建弹出按钮。
【问题讨论】:
标签: objective-c cocoa nspopupbutton