Basic Window Operation misunderstanding?
Basic Window Operation misunderstanding?
- Subject: Basic Window Operation misunderstanding?
- From: Paul Meyerholtz <email@hidden>
- Date: Wed, 17 Oct 2007 13:42:14 -0700
In my very first cocoa project I had a problem that I worked around.
But now going back to it, I don't see why my work around was necessary.
1. create a Cocoa Application
2. in IB add a Panel make it a Utility Window and visible at launch time
Run the application
The "main" Window initially is not displayed as the main window.
Once you click on it, it becomes main and stays main. I didn't like
this. I wanted it to be displayed as main from the start.
( why is this? when I first start an application shouldn't one of
the windows be the main window? The Panel cannot be so why isn't the
Window main? why do I need to click on it?)
First fix (sorry if I am too detailed in basic steps.. want to make
sure all steps are correct)
1. in IB add a new class, from NSObject, named "AppController"
2. instantiate it
3. in AppController create an Outlet, "theWindow" of type NSWindow
4. control drag from AppController to Window and connect "theWindow"
to the Window (not the Panel)
5. Create the AppController files
6. Add the following to AppController.m
- (void) awakeFromNib {
[theWindow makeMainWindow];
}
Build and Run. The program crashes. ???
2nd Fix
I had to create a subclass of NSWindow, override canBecomeMainWindow
to return YES, then finally everything worked.
This is contrary to the documentation which states when talking about
non standard windows:
"Such a window can be defined as a subclass of NSWindow that
overrides the methods canBecomeKeyWindow and canBecomeMainWindow to
return NO instead of the default of YES"
So a window is supposed to default YES to canBecomeMainWIndow, but my
program shows it defaulted as NO.
What did I do wrong?
Paul Meyerholtz
email@hidden
Mac Programming Tutorials
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden