• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
adding a new window and controller to a Document project on startup...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

adding a new window and controller to a Document project on startup...


  • Subject: adding a new window and controller to a Document project on startup...
  • From: Jon <email@hidden>
  • Date: Fri, 02 Oct 2009 15:04:28 -0600

On a standard Cocoa Document based project, I want to add a new window object/instance on startup (similar to adding a preference panel, but a permanent offscreen window)

as an experiment,  i did this below with a new onScreen window:

i get the new window to load alright on start up, but this disables the old Document class somehow?, not even the old init is called anymore??... I'm sure someone here can see quickly what i'm missing in this experiment process...
(or give me a quick lesson in how Cocoa document apps startup)


------------------------------------------------------------------------------------
start with a new Document based cocoa project..

add this new window controller class, also add a xib file that is nothing more than another window the same as the MyDocument.xib.... connect the new window to this new owner object

----------------------------------------
#import <Cocoa/Cocoa.h>

@interface MyDocument2 : NSWindowController
{
}
@end
----------------------------------------

#import "MyDocument2.h"

@implementation MyDocument2

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

- (NSString *)windowNibName
{
    return @"MyDocument2";
}

@end
----------------------------------------

in the main menu nib, added a new "object" and make it the "MyDocument2" object. so that this class loads on startup, and i get the window on startup.

in the old "MyDocument" class, i changed this as an experiment, maybe this is closer.
----------------------------------------
#import <Cocoa/Cocoa.h>
#import "MyDocumentController.h"


@interface MyDocument : NSDocument
{
}
@end
----------------------------------------

/*- (NSString *)windowNibName
{
    return @"MyDocument";
}*/

- (void)makeWindowControllers
{
MyDocumentController *controller = [[MyDocumentController alloc] initWithWindowNibName:@"MyDocument"];
[self addWindowController:controller];
[controller showWindow:nil]; //---------------- trying different things in here......
}
----------------------------------------


and then I added this class as part of the experimenting...

----------------------------------------
#import <Cocoa/Cocoa.h>

@interface MyDocumentController : NSWindowController
{
}

@end
----------------------------------------
#import "MyDocumentController.h"

@implementation MyDocumentController

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

- (NSString *)windowNibName
{
    return @"MyDocument";
}

@end
----------------------------------------

nothing from the original document class is being executed anymore?
this project loads the "MyDocument2" object window correctly, but then doesn't load the actual MyDocument object or it's window.


thanks for any help in advance on letting me know the fundamental thing i'm missing in how Cocoa document based apps start up..
Jon.
_______________________________________________


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


  • Prev by Date: Re: Spotlight index all data
  • Next by Date: Re: View shifted up on iPhone simulator
  • Previous by thread: Re: Spotlight index all data
  • Next by thread: Convert a per-doc window to inspector?
  • Index(es):
    • Date
    • Thread