Basic Window Operation misunderstanding?

  • 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
    <pholtz...>
    Mac Programming Tutorials
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today