Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SP-NewToMac

macrumors newbie
Original poster
May 11, 2009
8
0
Hello,

Apologies for the long email. Don't know enough about Mac development to ask the right questions. So want to give as much info as possible to describe my issue.

I have one main dialog which has three buttons that open three Panel windows. I have Controller classes (subclasses of NSWinController) for each of these panels that have closeButtonClicked method which simply calls [self close];

One of the three dialogs opens and closes fine. The other two dialogs just ignore the [self close] command. The panel stays open after clicking the close button. I have to use the red close button on the window bar to get rid of the window.

I see absolutely no differences in the controller code for the three panels and I followed the same method in creating the panels step by step as much as I can remember. Why do they behave differently?

Here is the main window controller code which has actions associated with three buttons on the main form.

Code:
- (IBAction)sendReport:(id)sender
{
    [self updateUserDefaults];
    NSString *steps = [tFieldStepByStep stringValue];
    NSLog(@"Step By Step is %@", steps);
    if (!progressDialog) {
        progressDialog = [[ProgressDialogController alloc] init];
    }
    
    NSLog(@"Show progress pane ");
    [progressDialog showWindow:self];
    //Build the XML
    [self buildDmpInfoXML];
}

- (IBAction)viewReportDetails:(id)sender
{
    if (!cerDetailsController) {
        cerDetailsController = [[CERDetailsController alloc] init];
    }
    
    NSLog(@"Show Details pane %@", cerDetailsController);
    [cerDetailsController showWindow:self];
}

- (IBAction)viewExampleDescription:(id)sender
{
    if (!exampleDescController) {
        exampleDescController = [[ExampleDescriptionController alloc] init];
    }
    
    NSLog(@"Show Example pane %@", exampleDescController);
    [exampleDescController showWindow:self];
}

Each of the panel controller headers have code very similar to this

Code:
#import <Cocoa/Cocoa.h>
#import <WebKit/WebView.h>

@interface ExampleDescriptionController : NSWindowController {
    //IBOutlet NSTextField *tFieldExampleDescription;
    IBOutlet WebView *webview;
}

-(IBAction)closeButtonClicked:(id)sender;
@end

Each panel controller has init method that loads the nib, and awakeFromNib has some logic to display right content.

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

closeButtonClicked has following code.

Code:
-(IBAction)closeButtonClicked:(id)sender
{
    [self close];
}

Why don't the windows close when I click on close button?

Thanks in advance for your help.
 
Code looks fine to me. Did you double-check your IB connections?

BTW, your init method could be simplified to this :)
Code:
-(id)init
{
    return [super initWithWindowNibName:@"ExampleDescription"];
}
 
Connections are ok.

The connections are fine because the [self close]; command gets executed after I click on the button. It just doesn't close the window. After struggling for a few hours I gave up and added [self autorelease]; command in closeButtonClicked method. But then I have to force [[CERDetailsController alloc] init]; every time the button gets clicked. It seems like a waste to kill the window completely and reinitialize every time, but works for now.

Also how do I kill the parent window from the panel? After closing one of the panels, I want to close the application completely. I added following code to the close method. It did not terminate the app.
[self close];
[self autorelease];
[NSApp terminate];
I obviously have a lot of reading to do here. I am probably not using the right controls and APIs. :)

Thanks for the tip on init. Makes sense.
 
Aren't you getting a compiler warning for [NSApp terminate], and an error at runtime? The method is terminate:, so it should be [NSApp terminate:nil]

I'm wondering if the bug is in your NSWindowController nibs.. maybe you have duplicate controllers. Can you post a screenshot of ExampleDescription.nib?
 
I did get an error. So I have removed the terminate command since. :p

Screenshots are attached. DetailsController is the one that does not close. Example description closes.
 

Attachments

  • DetailsController.png
    DetailsController.png
    65.3 KB · Views: 231
  • ExampleDescription.png
    ExampleDescription.png
    52.3 KB · Views: 234
Sorry, I meant the main nib window, where all the top-level objects are (Files Owner, windows, controllers, etc.). Sometimes weird bugs happen when multiple instances of a controller are created in a nib, so I just want to see if that could be the problem here.
 
Posting a solution on this thread since one was not forthcoming; make sure that in your custom NSWindowController subclass, you have connected the "window" property to the actual window in Interface builder.

The easiest way to do this in the most typical case, where the NSWindowController subclass is also "Files Owner" of the window's xib file, is to control-drag from "File's Owner" in Interface Builder onto the window, and then in the popup menu choose "Window" as the outlet.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.