• 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: Newbie question about NIBs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question about NIBs


  • Subject: Re: Newbie question about NIBs
  • From: tyler <email@hidden>
  • Date: Thu, 9 Aug 2001 11:16:14 -0700

Hey, I had similar problems when I tried this. There were a number of things wrong with my setup, not sure what it is with yours, here's some ideas:

but first, a debugging technique that helped me track down my issues when doing this: Set those break points like you are and then use the "po object" commands in the debugger console.
You can do things like: po [self window] to see if there is actually a window, etc.


1) Make the window visible in the IB attributes for the window (visible on launch I think it says). That'll probably fix it.

2) I initially had instantiated the window controller in my secondary nib file. But it seemed like what I really wanted was to make the file's owner be that window controller class, and NOT instantiate the window controller directly. To make the file owner be an instance of your window controller select the file controller (in instances pane in IB) and use the custom class pane of the info window.

3) I initially had my window controller class subclassed off of NSObject instead of NSWindowController and this really didn't work. Changing it in the .h file and then dragging the .h file back onto IB DOES NOT WORK in the case where it changes the base class. You have to delete the class from IB and then drag the .h file back onto it.

4) Make sure the "window" outlet on the windowcontroller (which will be your file owner) is attached to the instance of your Window.

Once I'd done all this, then both of either the visible on launch part worked, or using [self showWindow: self] in the window controller worked.


If you still don't have it working, use the debugging stuff to make sure all the outlets and objects are not null. If one is, try to figure out where it should have been set and that may give you a clue as to the problem.

If nothing else works, post again with the results of your research and we'll try to help you figure it out.

What you are trying to do basically works so it's not a bug in cocoa or something, just a goof in your code/nib somewhere.

luck,
tyler


On Thursday, August 9, 2001, at 06:19 AM, Jaime Rios wrote:

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!
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


References: 
 >Newbie question about NIBs (From: Jaime Rios <email@hidden>)

  • Prev by Date: Re: GNUStep compatability
  • Next by Date: Re: NSTextField update and multithreaded app
  • Previous by thread: Newbie question about NIBs
  • Next by thread: Re: cocoa-dev digest, Vol 1 #376 - 15 msgs
  • Index(es):
    • Date
    • Thread