1
我试图在NSTextField的最右侧添加一个NSButton图像。具体来说,它将是一个启动NSPopover(图形日期选择器日历)的按钮。现在我所要做的就是获取NSTextField最右侧的图像按钮。NSTextField中的NSButton子视图,为什么我的按钮不出现?
我有子类的NSTextField这样的,这里是我的代码:
@implementation myDateTextField {
- (void) awakeFromNib {
// my image button icon is 16px by 16px
NSRect buttonFrame = NSMakeRect(0.0f,0.0f, 16.0f, 16.0f);
NSButton *popoverButton = [[NSButton alloc] initWithFrame: buttonFrame];
popoverButton.buttonType = NSMomentaryChangeButton;
popoverButton.bezelStyle = NSInlineBezelStyle;
popoverButton.bordered = NO;
popoverButton.imagePosition = NSImageOnly;
[popoverButton setImage:[NSImage imageNamed:@"calendar_button.png"]];
[popoverButton.cell setHighlightsBy:NSContentsCellMask];
[self addSubview:popoverButton];
NSLog(@"awakeFromNib loaded.");
}
}
在Interface Builder中我已经设置了类我我的NSTextField被myDateTextField,我可以证实,awakeFromNib被调用时,我的窗口加载。我的问题是按钮并没有出现!
任何关于我可能做错什么的建议?我意识到按钮的位置可能会在文本字段内关闭,但现在我所要做的就是让它出现。
该死的。你是对的。我的监督甚至不检查是否为零。问题是它没有被加载。我将图像添加到我的项目中,但忘记将其添加到我的捆绑资源中。谢谢! – 2014-09-18 18:24:40
没问题,很高兴这是一个简单的修复! – RishiG 2014-09-18 18:31:10