Newbie question about NIBs
Newbie question about NIBs
- Subject: Newbie question about NIBs
- From: Jaime Rios <email@hidden>
- Date: Thu, 9 Aug 2001 09:19:27 -0400
Help!
I created an application ( cocoa ) in the project builder and in the first
NIB file I created the one window that I needed. In the original NIB file
for my project, I created an action called ShowSettings that is attached to
the 'Preferences' menu item in my NIB file. I then created a second NIB file
for my preference window and created all of the controls that I needed for
my app. I made all of the necessary attachments, instantiated the classes
and created the files for both NIB's. I went back to the project from the
Interface Builder and added the code that I needed to open the preference
window located in my second NIB file. The code looks like:
WNDController.h
#import <Cocoa/Cocoa.h>
#import "PrefsController.h" // For our preferences dialog box
@interface CPUController : NSObject
{
// Interface outlet
IBOutlet id pCPUGraph;
// Pointer to our preference panel
PrefsController* m_pPreferences;
}
- (IBAction)ShowSettings:(id)sender;
@end
WNDController.m
- (IBAction)ShowSettings:(id)sender
{
[m_pPreferences ShowPrefsDialog:self];
}
PrefsController.h
#import <Cocoa/Cocoa.h>
enum {
kHighUpdate,
kMediumUpdate,
kLowUpdate,
kPaused
};
@interface PrefsController : NSObject
{
int m_nAlwaysOnTop;
int m_nShowKernelTime;
int m_nUpdateRate;
id pPrefDialog;
// Interface building variables
IBOutlet id bAlwaysOnTop;
IBOutlet id bShowKernelTime;
IBOutlet id nUpdateRate;
}
- (void) LoadSettings;
- (void) updateUI;
- (IBAction)SetPrefs:(id)sender;
- (void) SetDefault;
- (void) ShowPrefsDialog:(id) sender;
@end
PrefsController.m
///////////////////////////////////////////////////////////////////
// This function actually displays the prefs dialog box
- (void)ShowPrefsDialog:(id)sender
{
if (!pPrefDialog)
{
if (![NSBundle loadNibNamed:@"Preferences" owner:self])
{
NSLog(@"Failed to load Preferences.nib");
NSBeep();
return;
}
[[pPrefDialog window] setExcludedFromWindowsMenu:YES];
[[pPrefDialog window] setMenu:nil];
[self updateUI];
[[pPrefDialog window] center];
}
[[pPrefDialog window] makeKeyAndOrderFront:nil];
}
When I run the app and select the 'Preferences' menu item, nothing happens.
I debug the app, and the Project Builder shows that the function is called
and runs, but nothing appears. What am I doing wrong? NOTE: if the
conventions used in this code look different that what you are used to
seeing, that's because I am a windows programmer trying to learn cocoa.
Thanks in advanced!