tags:

views:

53

answers:

1

Hi,

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).

A: 

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.

mustISignUp
No.I know longer have MainMenu.xib I deleted it because I am trying to figure how to do something without it.
thyrgle
You need it, it has the main menu in. Every Cocoa app has to have a main menu.
mustISignUp
Really, that seems so strange considering iPhone apps you don't need any .xibs technically. Are you sure? Because that does not seem to add up quite right.
thyrgle
Yes I'm sure. How many mac apps with gui can you count that don't have a menu bar?
mustISignUp
O yeah it does work when I create a new project and not delete the MainWindow.nib! Sorry, I'm just very skeptical and stubborn. And lazy. :P
thyrgle
haha yeah me too
mustISignUp