On 2009.04.13, at 11:15, Quincey Morris wrote:

Not exactly. Make your application delegate (let's say its class is MyAppDelegate) separate from your window controller. So, the steps are:

-- write a MyAppDelegate class (subclass of NSObject)

-- in IB, drag an object into MainMenu.xib, and set its class to MyAppDelegate (that causes an instance to be created automatically when your app starts up)

-- in IB, connect the 'delegate' outlet of the (predefined) Application object in MainMenu.xib to the MyAppDelegate object (that causes your MyAppDelegate object to actually *be* the application's delegate)

-- in your MyAppDelegate class, add an instance variable mainWindowController, of class MainWindowController

-- in your MyAppDelegate class, write an applicationDidFinishLaunching: method something like this:

- (void) applicationDidFinishLaunching: (NSNotification *) aNotification {
                mainWindowController = [[MainWindowController alloc] init];
                [mainWindowController showWindow: nil];
        }

-- your MainWindowController's init method should look something like this:

        - (id) init {
                self = [super initWithWindowNibName: @"MainWindow"];
                if (!self) ...
                ...
                return self;
        }

-- in IB, set the class of File's Owner in MainWindow.xib to MainWindowController

I may have left out something, but that's the basic idea.

It's working !
Thank you!

Tell me please should and in what cases would I keep MyAppDelegate separate from MainWindowController and in what not, because I kinda made it work all from one place:

#import <Cocoa/Cocoa.h>


@interface MainWindowController : NSObject
{
        NSWindowController *mainWindowController;
}

@end
________________________________________________________________________________

#import "MainWindowController.h"


@implementation MainWindowController

- (void) applicationDidFinishLaunching:(NSNotification *) aNotification
{
mainWindowController = [[NSWindowController alloc] initWithWindowNibName:@"MainWindow"];
        [mainWindowController showWindow:nil];
}

@end

And about delegates, so if I want to do something else now I have to create another object in MainMenu.nib and make it a delegate of proxy object Application again ?
There can be multiple delegations for one Application object ?
Or should I make one object that will be a delegate but will hold the code for all other stuff ?
Could you explain this to me a little bit more ?

Thanks !

Mario

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to