使用 loadNibNamed 后无法访问任何插座
编辑:如果有人想查看实际代码,这里是: http://pastie.org/713951
长话短说:我的问题我的问题是我无法使窗口显示在 Fly() 函数中。
完整描述:
我正在为 Mac 应用程序“Coda”创建一个插件。我有一个控制器“Bolder”,有两个出口:
@class Bolder;
@interface Bolder : NSObject
{
IBOutlet id MyLabel;
IBOutlet id theWindow;
}
Coda 为插件指定了它自己的 init 方法。 init 方法中,我正在加载 Nib 'Superman' 并选择单击我的插件时要调用的方法 'fly':
[NSBundle loadNibNamed:@"Superman" owner:self];
[controller registerActionWithTitle:NSLocalizedString(@"OK!", @"Flying Man") target:self selector:@selector(fly:)];
在 'fly' 方法中,我想显示窗口并更改标签上的文本:
- (void)fly:(id)sender
{
[theWindow orderFront:self];
[theWindow makeKeyAndOrderFront:self];
[MyLabel setStringValue:@"new text"];
}
在此 最后一点是让我困惑的部分——窗口就是不显示!然而,如果我将这三行内容放入“awakeFromNib”中,它会显示得很好。是什么造成了这种差异?我无法将此代码放入 awakeFromNib 中,因为这会导致每次启动 Coda 时都会显示我的插件窗口。
Edit: In case someone wants to look at the actual code, here it is:
http://pastie.org/713951
Long story short: the problem I'm having is I can't make the window show up in the fly() function.
Full Description:
I'm creating a plugin for the Mac application 'Coda'. I have a controller 'Bolder', with two outlets:
@class Bolder;
@interface Bolder : NSObject
{
IBOutlet id MyLabel;
IBOutlet id theWindow;
}
Coda specifies it's own init method for plugins. In this init method, I am loading a Nib 'Superman' and choosing a method 'fly' to call when my plugin is clicked:
[NSBundle loadNibNamed:@"Superman" owner:self];
[controller registerActionWithTitle:NSLocalizedString(@"OK!", @"Flying Man") target:self selector:@selector(fly:)];
In the 'fly' method, I want to show the window and change the text on a label:
- (void)fly:(id)sender
{
[theWindow orderFront:self];
[theWindow makeKeyAndOrderFront:self];
[MyLabel setStringValue:@"new text"];
}
This last bit is the part that is throwing me – the window just doesn't show up! Yet if I put these same three lines inside 'awakeFromNib' it shows up fine. What's causing this difference? I can't put this code inside awakeFromNib because that causes my plugin's window to show up every time I start Coda.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试延迟笔尖加载,直到显示窗口为止。例如:
Try delaying you nib loading until it's time to show the window. E.g.:
如果您不希望在加载笔尖时显示该窗口,请在 Interface Builder 中取消选中该窗口的“启动时可见”。
Uncheck "Visible At Launch" for the window in Interface Builder if you don't want it to show when you load the nib.