Objective-C:窗口未声明
这将是一个菜鸟问题,但我对此感到疯狂。我读过很多主题,但我认为我错过了一些主要内容。
我创建了新的 cocoa 应用程序项目,没有更改任何内容,只需将下一个代码添加到 main.m
int main(int argc, char *argv[])
{
NSView *superview = [window contentView];
NSRect frame = NSMakeRect(10, 10, 200, 100);
NSButton *button = [[NSButton alloc] initWithFrame:frame];
[button setTitle:@"Click me!"];
[superview addSubview:button];
[button release];
return NSApplicationMain(argc, (const char **) argv);
}
在编译 xcode 期间告诉我该窗口未声明。我知道,而不是 window 应该是我的 NSWindow 对象的名称,但我不明白哪个名称具有在 MainMenu.xib 文件中自动创建的 NSWindow 。
请帮忙,我几乎准备好用我的头打破墙壁了。
It will be a noob question, but i'm getting crazy with this. I've read a tons of topics but i think i am missing something main.
I`ve created new cocoa app project, did not change anything, just add next code to main.m
int main(int argc, char *argv[])
{
NSView *superview = [window contentView];
NSRect frame = NSMakeRect(10, 10, 200, 100);
NSButton *button = [[NSButton alloc] initWithFrame:frame];
[button setTitle:@"Click me!"];
[superview addSubview:button];
[button release];
return NSApplicationMain(argc, (const char **) argv);
}
During compiling xcode tells me that window undeclared. I understand that instead of window should be name of my NSWindow object, but i don`t understand which name has NSWindow which automatically created in MainMenu.xib file.
Please help, i`m almost ready to broke the wall with my head.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此时还没有创建任何窗口。 Xcode 生成的代码会在项目应用程序委托中为您提供
window
,因此请将您的代码添加到YourProjectAppDelegate.m
中的-applicationDidFinishLaunching:
中。< br>我建议从一些介绍性材料开始,例如Hillegass 应该详细介绍此类内容。
At that point no window has even been created yet. The code generated by Xcode gives you
window
in your projects application delegate, so add your code to-applicationDidFinishLaunching:
inYourProjectAppDelegate.m
instead.I recommend to start with some introductory material like Hillegass where such things should be covered in detail.