简体   繁体   English

Objective-C:未声明窗口

[英]Objective-C: window undeclared

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 我已经创建了新的可可应用程序项目,没有做任何更改,只需将下一个代码添加到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. 在编译xcode时告诉我未声明窗口。 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. 我知道不是窗口应该是我的NSWindow对象的名称,但是我不知道哪个名称具有在MainMenu.xib文件中自动创建的NSWindow。

Please help, i`m almost ready to broke the wall with my head. 请帮忙,我几乎准备好用头撞墙。

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: in YourProjectAppDelegate.m instead. Xcode生成的代码为您提供了项目应用程序委托中的window ,因此请将您的代码添加到YourProjectAppDelegate.m -applicationDidFinishLaunching:中。
I recommend to start with some introductory material like Hillegass where such things should be covered in detail. 我建议从Hillegass之类的介绍性材料开始,其中应详细介绍这些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM