NSWindow 不显示

发布于 2024-09-07 16:57:08 字数 1208 浏览 2 评论 0原文

我在尝试不使用 Interface Builder 显示 NSWindow 时遇到问题。窗口的初始化非常混乱,因为我更熟悉 iPhone(它没有 NSWindow 等效项)。所以我在 Google 上搜索了一些代码,最终找到了这个:

NSRect windowRect = NSMakeRect(10.0f, 10.0f, 800.0f, 600.0f);

NSWindow *window = [[NSWindow alloc] initWithContentRect:windowRect 
                                               styleMask:( NSResizableWindowMask | NSClosableWindowMask | NSTitledWindowMask) 
                                                 backing:NSBackingStoreBuffered defer:NO];

[window makeKeyAndOrderFront:nil];

所以我复制了该代码并将其放在 applicationDidFinishLaunching 中,并认为一切都会好的。但一切都不好。 Xcode 在构建结果中未显示任何错误(或警告)。但是,我确实在显示日志中收到了这条消息:

2010-06-26 13:33:47.170 FooApp[283:a0f] Could not connect the action buttonPressed: to target of class NSApplication

我不知道如何解释这一点,因为谷歌在搜索此显示日志错误的解决方案时失败了。而且,据我所知,我目前没有任何操作,包括 buttonPressed 操作。附带说明:我不知道这是否相关,但我删除了 Main Window.xib 及其在 info.plist 中的随附属性。

任何帮助将不胜感激。

更新:我尝试进行一些 printf 调试(从来没有真正费心学习 NSLog),如果事情位于在 appliactionDidFinishLaunching 的最开始,或者更糟糕的是,在 main 的开始(在返回之前,如果你们中的一些人想问我是否将 printf 放在之前或之后) return 语句)。

I am having a trouble try to display a NSWindow with out using Interface Builder. The initialization of the window was quite confusing since I am more familiar with iPhone (which does not have an NSWindow equivalent). So I searched Google for some code and I eventually found this:

NSRect windowRect = NSMakeRect(10.0f, 10.0f, 800.0f, 600.0f);

NSWindow *window = [[NSWindow alloc] initWithContentRect:windowRect 
                                               styleMask:( NSResizableWindowMask | NSClosableWindowMask | NSTitledWindowMask) 
                                                 backing:NSBackingStoreBuffered defer:NO];

[window makeKeyAndOrderFront:nil];

So I copied that code and placed it in the applicationDidFinishLaunching and thought all would be good. But all is not good. Xcode did not display any errors (or warnings) in the Build Results. But, I do get this message in the display log:

2010-06-26 13:33:47.170 FooApp[283:a0f] Could not connect the action buttonPressed: to target of class NSApplication

I don't know how to interpret this as Google has failed me on searching for a solution on this display log error. And, as far as I can tell, I have no actions at the moment including a buttonPressed one. As a side note: I do not know if this is relevant or not, but I deleted the Main Window.xib and its accompanying property in the info.plist.

Any help would be greatly appreciated.

UPDATE: I tried doing some printf debugging (never really bothered learning NSLog) and the thing won't even printf if the thing is at the very beginning of the appliactionDidFinishLaunching or even worst, at the start of main (before the return if incase some of you are tempted to ask me if I put the printf before or after the return statement).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2024-09-14 16:57:14

MainWindow.xib 是 iphone 应用程序模板的一部分,不是吗?你到底删除了什么?你还有 MainMenu.xib,对吗?

正如您所发现的,对于 Cocoa 应用程序来说,拥有 nib 文件不是可选的。您必须至少有一个笔尖(或 xib,对于您的孩子来说),并且其中必须有一个主菜单。

MainWindow.xib is part of the iphone App template, isn't it? What exactly did you delete? You still have the MainMenu.xib, right?

As you have discovered, having a nib file is not optional for a Cocoa app. You must have at least one nib (or xib, for you youngsters) and it must have a main menu in it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文