Re: How to open two nibs at app launch ? Beginners question
Re: How to open two nibs at app launch ? Beginners question
- Subject: Re: How to open two nibs at app launch ? Beginners question
- From: Filip van der Meeren <email@hidden>
- Date: Mon, 13 Apr 2009 17:29:24 +0200
On 13 Apr 2009, at 17:21, Michael Ash wrote:
On Mon, Apr 13, 2009 at 6:27 AM, Mario Kušnjer
<email@hidden> wrote:
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;
}
Instead of overriding the init method, you could override windowNibName
- (NSString*)windowNibName { return @"MyNibName"; }
and then just call your WindowController alloc init methods...
-- 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 ?
Read the part about delegation in Cocoa Fundamentals Guide:
Communicating with Objects:
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html
While you're at it, read the whole guide, it's quite good and will
explain a lot of things.
Mike
_______________________________________________
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
_______________________________________________
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