Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5938373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:40:35+00:00 2026-05-22T15:40:35+00:00

I have an NSDocument subclass with two NSWindowControllers corresponding to 2 different xib. Following

  • 0

I have an NSDocument subclass with two NSWindowControllers corresponding to 2 different xib.

Following the Document-Based Application Guide I have added the following in my document.m implementation

- (void)makeWindowControllers 
{
    NSLog(@"in MakeWindowControllers");

    MainWindowController *mainWindowController = [[MainWindowController alloc] init];
    [mainWindowController autorelease];
    [self addWindowController:mainWindowController];

    csvWindowController = [[CSVWindowController alloc] init];
    [csvWindowController autorelease];
    [self addWindowController:csvWindowController];        
}

Problem is I want the second window controller csvWindowController to hide its window initially, I will show the same instance of the window later on. To do so I have written:

@implementation CSVWindowController


- (id) init {

    if ( ! (self = [super initWithWindowNibName:@"CSVWindow"]) ) {

        NSLog(@"CSVWindowController init failed");
        return nil;
    }

    window = [self window];
    NSLog(@"CSVWindowController init");

    [window orderOut:nil]; // to hide it
    NSLog(@"CSVWindowController hiding the window");

    return self;
}

But the window is there, showing up.

Please not I have the VisibleAtLaunch not flagged, that console it’s showing my messages correctly, and that even if I change:

        [window orderOut:nil]; // to hide it
to 
        [window orderOut:self]; // to hide it

The result is the same, window showing up.

Any help is appreciated, thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:40:36+00:00Added an answer on May 22, 2026 at 3:40 pm

    Ok, again I reply to my own question, but this time with a positive remark. I think what I was doing wrong had something to do with the hidden – for me – implications of the Document-based architecture of the default Document Application template.

    I have tried with a different approach, creating an application from scratch NOT flagging “Document-based Application” and providing it with:

    • 1 NSDocument subclass
    • 2 NSWindowControllers subclasses
    • 1 MainMenu.xib
    • 2 window.xib

    and I have forced instantiation of the NSWindowController subclasses in the MyDocument code.

    I have also put the IBActions for the MenuItems in the MyDocument and I have bound the MyDocument Object to the MenuItems in the MainMenu.xib.

    This time I was able to do whatever, hiding/showing windows starting with one hidden one not, enabling menu items automatically at will.

    Here follows the code, for any newbie like me who might have to fight with this in the future.

    //  MyDocument.h
    #import <Cocoa/Cocoa.h>
    #import "testWindowController.h"
    #import "test2WindowController.h"
    
    @interface MyDocument : NSDocument {
        testWindowController *test;
        test2WindowController *test2;
    
    }
    
    - (IBAction)showWindow1:(id)pId;
    - (IBAction)showWindow2:(id)pId;
    - (IBAction)hideWindow1:(id)pId;
    - (IBAction)hideWindow2:(id)pId;
    
    @end
    
    
    //  MyDocument.m
    #import "MyDocument.h"
    #import "testWindowController.h"
    #import "test2WindowController.h"
    
    @implementation MyDocument
    
    - (id)init
    {
        self = [super init];
        if (self) {
            // Initialization code here.
            NSLog(@"MyDocument init...");
            [self makeWindowControllers];
        }
    
        return self;
    }
    
    - (void)dealloc
    {
        [super dealloc];
    }
    
    - (void)makeWindowControllers 
    {
    
        test = [[testWindowController alloc] init];
        test2 = [[test2WindowController alloc] init];  
    
        [self addWindowController:test];
        [self addWindowController:test2];
    
        // start hiding the first window
        [[test window] orderOut:self];
    }
    
    - (IBAction)hideWindow1:(id)pId
    {
        NSLog(@"hideWindow1");
        [[test window] orderOut:self];
    }
    
    - (IBAction)showWindow1:(id)pId
    {
        NSLog(@"showWindow1");
        [test showWindow:self];
        [[test window] makeKeyAndOrderFront:nil]; // to show it
    }
    
    - (IBAction)hideWindow2:(id)pId
    {
        NSLog(@"hideWindow2");
        [[test2 window] orderOut:self];
    }
    
    - (IBAction)showWindow2:(id)pId
    {
        NSLog(@"showWindow2");
        [test2 showWindow:self];
        [[test2 window] makeKeyAndOrderFront:nil]; // to show it
    }
    
    
     -(BOOL)validateMenuItem:(NSMenuItem *)menuItem {
    
         NSLog(@"in validateMenuItem for item: %@", [menuItem title]);
    
         if ([[menuItem title] isEqualToString:@"Show Window"] 
             && [[test window] isVisible]){
             return NO;
         }
    
         if ([[menuItem title] isEqualToString:@"Hide Window"] 
             && ![[test window] isVisible]){
             return NO;
         }
    
         if ([[menuItem title] isEqualToString:@"Show Window2"] 
             && [[test2 window] isVisible]){
             return NO;
         }
    
         if ([[menuItem title] isEqualToString:@"Hide Window2"] 
             && ![[test2 window] isVisible]){
             return NO;
         }
         return [super validateMenuItem:menuItem];
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document-based application and I have sub-classed NSDocument and provided the required
I have a NSDocument based application with a nib that represents the visual document.
I have a NSDocument based application, which allows the user to send messages, after
I'm wondering if NSDocument is only for applications that are text/document-based. I have an
I have an document-based Cocoa application with a TextView and I would like to
I have a document-based Cocoa application that has to start up a sub-process before
I am working on a document-based Cocoa application. At startup, the user is presented
I have a straightforward NSDocument -based Mac OS X app in which I am
I have an NSDocument which has the following structure: @interface MyDocument : NSDocument {
I have a document-based Cocoa app. During runtime, I load an additional nib from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.