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 6836207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:19:42+00:00 2026-05-26T23:19:42+00:00

I am looking for the simplest example which shows one window opening another window

  • 0

I am looking for the simplest example which shows one window opening another window and then closing it.

The place where I seem to get stuck is with the NIBs and how the outlets should be wired. I can easily get the window created; closing it presents a challenge.

Any advice much appreciated!

I’m attaching my code below. I think what I am trying to do is simple, yet it doesn’t work. Thanks to Francis I can now get the window to open and close but once I try to open it again the application crashes (EXC_BAD_ACCESS). I’m sure this is due to my poor understanding of the NIB relationship to classes. In most languages I would just need to instantiate a new instance of a window and then close it.

I have 2 windows in MainMenu.xib. (I’d prefer to have the window in a separate NIB but that appears to create other problems!) The AppDelegate has 2 outlets, to window (original) and otherWindow (2nd window created).

The first window has 2 buttons: “Open Window” and “Close Window” with connections to the 2 methods in the code.

Code:

MyTestAppDelegate.h

#import <Cocoa/Cocoa.h>

@interface MyTestAppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
    NSWindow *otherWindow;
}

@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSWindow *otherWindow;

- (IBAction)openOtherWindow:(id)sender;
- (IBAction)closeOtherWindow:(id)sender;

@end

MyTestAppDelegate.c

#import "MyTestAppDelegate.h"

@implementation MyTestAppDelegate

@synthesize window;
@synthesize otherWindow;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
}

- (IBAction)openOtherWindow:(id)sender
{
    [otherWindow makeKeyAndOrderFront:sender];
}

- (IBAction)closeOtherWindow:(id)sender
{
    [otherWindow close];
}
@end
  • 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-26T23:19:43+00:00Added an answer on May 26, 2026 at 11:19 pm

    Basically, in your NIB you create the various windows, add your buttons, textfields, etc. Then you add a custom object that acts as a “controller” that sends and receives messages to and from the windows and various controls. In a simple project you can use the automatically-created AppDelegate object to control your windows, for bigger projects you want a separate object to handle the logic, which can be an instance of NSObject or NSWindowController, depending on your needs.

    Windows can be set up as “Visible at launch” which opens them when your app launches. You can also open them manually by creating IBOutlet references in the header files and connecting them in the NIB. To show windows you send them a makeKeyAndOrderFront: message. To close them you send them a close method.

    To respond to window opening/closing you assign your controller object as the windows’ “delegate”, which means it will recieve messages from the windows, which are listed in the documentation under the NSWindowDelegate protocol. So if you wanted to open a window in response to another window closing, you would listen for the windowWillClose: message and tell the other window to open, and vice-versa.

    This is pretty basic stuff so I recommend you read the Hillegass book, or browse some of the various tutorials available online.

    EDIT:

    You’re application is crashing because you have your otherWindow set to “Release when closed” Since you are in a memory-managing environment, and nothing is retaining the window, the next time you try to open it it has already been freed. The solution is to uncheck “Release When Closed” in the NIB file. Notice you can also connect your button actions to makeKeyAndOrderFront: and performClose: methods of the other window itself, directly in the NIB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for the simplest way to get notified when successful installation of
Looking for the simplest way to get a single value from a database. This
I'm looking for a simplest (and fastest) example of TCP socket programming for windows,
I'm looking for the simplest, most straightforward way to implement the following: The main
I am looking for the simplest php framework that comes integrated with dojo. I
I'm looking for a simplest way to remove duplication in my WPF code. Code
I am looking for a drop-down JavaScript menu. It should be the simplest and
Looking for an example that: Launches an EXE Waits for the EXE to finish.
Looking for C# class which wraps calls to do the following: read and write
What is simplest way to assign a bit mask to integer value? For example

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.