• 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
Preference panel appears one but not the second time?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Preference panel appears one but not the second time?


  • Subject: Preference panel appears one but not the second time?
  • From: Bob Ueland <email@hidden>
  • Date: Wed, 5 Dec 2007 07:05:45 -0800 (PST)

I'm trying to make an app with an empty window and an empty Preference panel that is activated when user choses Preferences... from the menu. I've tried to accomplish that with the following code:

//
//  AppController.h
#import <Cocoa/Cocoa.h>
@class PreferenceController;

@interface AppController : NSObject {
    PreferenceController *preferenceController;
}
- (IBAction)showPreferencePanel:(id)sender;
@end


//
//  AppController.m
#import "AppController.h"
#import "PreferenceController.h"

@implementation AppController

- (IBAction)showPreferencePanel:(id)sender
{
    // Is preferenceController nil?
    if (!preferenceController) {
       preferenceController = [[PreferenceController alloc] init];
    }
    [preferenceController showWindow:self];
}

- (void)dealloc
{
    [preferenceController release];
    [super dealloc];
}
@end

//--------------------

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

@interface PreferenceController : NSWindowController {

}
@end


//
//  PreferenceController.m
#import "PreferenceController.h"

@implementation PreferenceController
- (id)init
{
    self = [super initWithWindowNibName:@"Preferences"];
    return self;
}
- (void)windowDidLoad
{
    NSLog(@"Nib file is loaded");
}
@end



I'm using Leopard. In the IB, I've done done following

1. From Controllers I drag and dropped a blue box NSObject and chose AppController as its class.

2. From IB menu chose File/New.. and chose Cocoa/Empty. Saved as Preference.nib in the same directory as MainMenu.nib. (I thought that maybe IB would add this file automatically to my project, but it didn't do it so I dragged it manually from Finder to Resources in Xcode).

3. From XCode dragged PrefrenceController.h to Preferences.nib in IB. I then set File's owner to PreferenceController.

4. Dragged a Panel from Objects/Application/Windows  and dropped it on the screen. A Panel icon appeared in the Preferences.nib.

5. I then built and run. An empty window appeared. I chose Preferences... from the menu and the Preference panel appeared. I closed the Preference panel and tried to open it again by choosing Preferences... from the menu. But the panel didn't appear. What is the explanation??

Here are some clues

If I change
   if (!preferenceController) {
      preferenceController = [[PreferenceController alloc] init];
   }


to
     //if (!preferenceController) {
      preferenceController = [[PreferenceController alloc] init];
   //}


then the app works. However the preference panel does not become activated unless I click on it.

Thanks Bob




      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs
_______________________________________________

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

  • Follow-Ups:
    • Re: Preference panel appears one but not the second time?
      • From: Fritz Anderson <email@hidden>
  • Prev by Date: Re: How to Make a Very Thin Window? - Solved
  • Next by Date: Re: Preference panel appears one but not the second time?
  • Previous by thread: Re: [Leopard] CIContext thread safety [was: CGContextDrawShading crash a known problem?]
  • Next by thread: Re: Preference panel appears one but not the second time?
  • Index(es):
    • Date
    • Thread