• 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
Re: Preferences in a separate nib file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Preferences in a separate nib file


  • Subject: Re: Preferences in a separate nib file
  • From: Derrick Bass <email@hidden>
  • Date: Sun, 6 Nov 2005 23:54:46 -0500

On Nov 6, 2005, at 4:00 AM, Conor Dearden wrote:


What Cameron said is correct; there does not exist a no code way. He is
actually allocating a custom class and never loads a nib. It's the same
setup Cameron mentioned but the class method to load the nib is "[NSBundle
loadNibNamed:owner:"


- (IBAction)showPreferences:(id)sender {

    if (preferencesObject == nil) {
        preferencesObject= [[MyPreferences alloc] init];
        if (![NSBundle loadNibNamed:@"PreferencesPanel.nib"
owner:preferencesObject] ) {
            NSLog(@"Load of PreferencesPanel.nib Failed");
            return;
        }
    }

    [[preferencesObject window] makeKeyAndOrderFront: self];
}

As you can see I also load a custom object but then load it as the owner of
a new nib. If you don't mind the object who has method "showPreferences:"
(typically some kind of central controller) being the owner you can do:





If I might ask, what are the downsides to that? The upside seems to be not having to declare another object to own the preferences window.



- (IBAction)showPreferences:(id)sender {

if (preferencesWindow == nil) {
if (![NSBundle loadNibNamed:@"PreferencesPanel.nib" owner:self] ) {
NSLog(@"Load of PreferencesPanel.nib Failed");
return;
}
}
[preferencesWindow makeKeyAndOrderFront: self];
}


Whatever class you pass as owner remember to set it as the class of the file
owner in the nib file and connect your outlets like preferenceWindow.



Hmm... I had to play with this for quite a while. My nib was named "Preferences.nib" and this turned out to be the problem. "Prefs.nib" and "Test.nib" and several other names worked fine. Any idea what that's about? (The nib was loaded successfully, but the preferencesWindow outlet was never connected.)

Anyway, thanks everyone. I think I'm finally starting to wrap my head around what's on under the hood in Cocoa.

Conor Dearden
http://www.bruji.com/






Cameron Hayne wrote:


I think you need some code to hook it up to your main controller.
For example, here is what I have in the main controller of my
document-based app that has a preferences window in a separate nib
that is loaded by its own preferences controller.

- (IBAction)showPreferences:(id)sender
{
     NSLog(@"IsingController.showPreferences");
     if (preferencesCtl == nil)
     {
         preferencesCtl = [[IsingPreferencesCtl alloc] init];
     }

     [[preferencesCtl window] makeKeyAndOrderFront: self];
}










_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Preferences in a separate nib file
      • From: Conor Dearden <email@hidden>
References: 
 >Re: Preferences in a separate nib file (From: Conor Dearden <email@hidden>)

  • Prev by Date: Processing multiple objects w/NSTasks efficiently?
  • Next by Date: Re: Processing multiple objects w/NSTasks efficiently?
  • Previous by thread: Re: Preferences in a separate nib file
  • Next by thread: Re: Preferences in a separate nib file
  • Index(es):
    • Date
    • Thread