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

  • SEARCH
  • Home
  • 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 7863739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:34:43+00:00 2026-06-02T23:34:43+00:00

I have an issue with an NSPanel acting strangely and have created a Sample

  • 0

I have an issue with an NSPanel acting strangely and have created a Sample App to demonstrate this behaviour.

The App was generated from Xcode 4’s template and simply creates a panel and then opens and closes it based on button presses:

enter image description here

The strange behaviour I have observed:

  1. Under Lion, after opening the panel for the first time, the panel follows the main window around, which is correct behaviour. However after closing it and then re-opening it no longer follows the main window around.
  2. Under Snow Leopard, when closing the panel the main window is also closed!

EDIT: Just to be clear; the behaviour I expect is for the panel to follow the main window around when the main window is moved; and for that to be true after the panel is closed and subsequently re-opened. Also I expected the panel and main window to behave the same way under Snow Leopard and Lion.

The important part of the code is here:

@implementation MyAppDelegate

- (void)dealloc
{
    [_panel release];
    [super dealloc];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    _panel = [[NSPanel alloc]
             initWithContentRect:NSMakeRect(400, 400, 200, 100)
             styleMask:NSUtilityWindowMask|NSClosableWindowMask|NSTitledWindowMask
             backing:NSBackingStoreBuffered
             defer:YES];
    [_panel setTitle:@"A Panel"];
}

- (IBAction)openPanel:(id)sender
{
    [_panel setParentWindow:[self window]];
    [_panel makeKeyAndOrderFront:sender];
}

- (IBAction)closePanel:(id)sender
{
    [_panel orderOut:sender];
}

@end

Note: I added the unnecessary setParentWindow call to the openPanel method to assert that the parent window is reset every time the panel was opened; it made no difference however.

Can someone please explain what I’m doing wrong?

EDIT: There is some confusion about the missing @synthesize window = _window from the implementation file, but I have just opened another project sample that I created to test for memory leak behaviour and it’s not in there either. I am using Xcode 4.4, so it’s possibly a bug in that, however I don’t think the project templates have changed.

  • 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-06-02T23:34:46+00:00Added an answer on June 2, 2026 at 11:34 pm

    You’re not supposed to set the parent-child relationship from the child, but from the parent. The setParentWindow: docs say:

    This method should be called from a subclass when it is overridden by a subclass’s implementation. It should not be called otherwise.

    Instead, use addChildWindow:ordered:, like so:

    - (IBAction)openPanel:(id)sender
    {
        [[self window] addChildWindow:_panel ordered:NSWindowAbove];
        //[_panel setParentWindow:[self window]];
        [_panel makeKeyAndOrderFront:sender];
    }
    

    I didn’t test this under Snow Leopard, but it fixes the behavior for me when run on Lion.

    Rob Keniger notes below that on Snow Leopard you should also do [[self window] removeChildWindow:_panel] before ordering the panel out. (I assume this is also a good idea on Lion.)

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

Sidebar

Related Questions

Much of my sql code is generated (from POD). Now i have issue where
I have an issue about writing HTML file with PHP. I have this function
Have another issue here. Our app starts out with a tab activity. But, before
I need your help on one practical issue. I have created a WCF service
Seems like everyone have issue accessing local machine or internet etc from emulator. All
I have an issue in iOS with a HTML5 Offline app. My app works
We have an issue using the PEAR libraries on Windows from PHP . Pear
I have issue with my inner join division below. From my oracle, it keep
I have issue with displaying AlertDialog from Service. I am able to display custom
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So

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.