Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 29, 2009, 11:43 AM   #1
cromestant
macrumors member
 
Join Date: Apr 2006
basic secondary NIB question[SOLVED]

Hello, I'm currently learning on my own how to program in cocoa, and its quite fun, but i ve run into a few little problems, and I would love some help.


Ok, so first of all , i have My main window nib file with a button that uppon beeing pressed lauches a secondary window. This secondary window is an instance of NSWindowController, it launches properly with this code

Code:
@interface NewBill : NSWindowController {
	
}
Code:
//
//  NewBill.m
//  Facturacion
//
//  Created by Charles Romestant on 1/28/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "NewBill.h"


@implementation NewBill

- (id) init {
	
	if ( ! (self = [super initWithWindowNibName: @"nibFactura"]) ) {
		NSLog(@"init failed in TheWindowController");
		return nil;
	} // end if
	NSLog(@"init OK in TheWindowController");
	return self;
} // end init

- (void)windowDidLoad {
	NSLog(@"TheWindowPanel did load");
	
} // end windowDidLoad


@end
and from my mainAppController :
Code:
//
//  AppController.m
//  Facturacion
//
//  Created by Charles Romestant on 1/28/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "AppController.h"
#import "NewBill.h"

@implementation AppController

-(IBAction) showTheWindow:(id)pId;
{
	NSLog(@"Hi from TheAppController showTheWindow");
	if (! BillWindow ) {
		BillWindow	= [[NewBill alloc] init];
	} // end if
	
	[BillWindow showWindow:self];
}
@end
Now, on this secondary window i decided to add a textfield so that i can "fill" it when the window loads ( so that later on i can fill it with precalculated values from a sqlite file).
so I added the outlet on the .h file, added an NSObject from the interface builder, set its type to the NWwindowController class ( NewBill)

set the link in interface builder and added this
in the header :
Code:
IBOutlet NSTextField *numControl;
Code:
[numControl setStringValue:@"Loaded from NewBill.m"];
So the compiel works, no errors, no warnings, my button still spawns the new window, but no text is in the NSTextField.

what could be going on?

Last edited by cromestant; Jan 30, 2009 at 06:11 PM. Reason: SOLVED
cromestant is offline   0 Reply With Quote
Old Jan 29, 2009, 02:42 PM   #2
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Where is that line of code that sets the string value of the text field? What happens when you call that in windowDidLoad:? And what's it say if you check the outlet for nil before calling it?
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Jan 29, 2009, 02:46 PM   #3
cromestant
Thread Starter
macrumors member
 
Join Date: Apr 2006
i m sorry i did not repost it all, here is the code with the outlet beeing used

Code:
//
//  NewBill.m
//  Facturacion
//
//  Created by Charles Romestant on 1/28/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "NewBill.h"


@implementation NewBill

- (id) init {
	
	if ( ! (self = [super initWithWindowNibName: @"nibFactura"]) ) {
		NSLog(@"init failed in TheWindowController");
		return nil;
	} // end if
	NSLog(@"init OK in TheWindowController");
	return self;
} // end init

- (void)windowDidLoad {
	NSLog(@"TheWindowPanel did load");
	[numControl setStringValue:@"Loaded from NewBill.m"];
} // end windowDidLoad


@end
cromestant is offline   0 Reply With Quote
Old Jan 30, 2009, 06:11 PM   #4
cromestant
Thread Starter
macrumors member
 
Join Date: Apr 2006
moved it to the awakeFromNib file and it works like a charm@
cromestant is offline   0 Reply With Quote
Old Jan 30, 2009, 08:53 PM   #5
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
That's cool that it works, but I'm still confused as to why it's not working in windowDidLoad: as well. I *thought* that outlets were guaranteed to be valid when that gets called, in other words after awakeFromNib:, but apparently not. So I guess using awakeFromNib: makes sense, because we do know that in that method at least, all connected outlets are guaranteed to be valid. Then there's windowControllerDidLoadNib: as well. There's a little about that stuff here, but it's not entirely clear to me from that what the calling order is.
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Jan 30, 2009, 09:45 PM   #6
cromestant
Thread Starter
macrumors member
 
Join Date: Apr 2006
I'm postign from my phone s I don't have the link at hand but aparently outlets might not have been initializd on that call. Plus it only gets called once so it's not what I need awake from nib is what I need i'll post links Tomorow.
__________________
unibodyMacbook, 4gb ram, 20gb 4th gen ipod photo, 2d gen ipod shuffle, AEBS, 40gb tv,g4-mini, like 4 keyboards,mighty mouse, 1stgen Iphone.
cromestant is offline   0 Reply With Quote
Old Jan 31, 2009, 01:03 PM   #7
cromestant
Thread Starter
macrumors member
 
Join Date: Apr 2006
ok, this is the link that i got that made me move to awakeFromNib method instead. ( it makes sense actually).

Click me !

Also, what happens, is that awakeFromNib gets called on every spawn of the window, whereas the other only gets called on the first time, so for instance if you want to calculate a value that is needed on your new window ( for instance to pre-fill a value with an id or such, then you d only get it on the first time, and not on all other instances.
__________________
unibodyMacbook, 4gb ram, 20gb 4th gen ipod photo, 2d gen ipod shuffle, AEBS, 40gb tv,g4-mini, like 4 keyboards,mighty mouse, 1stgen Iphone.
cromestant is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Question about secondary monitor and 15 rMBP?!? jomirrivera MacBook Pro 5 Jan 19, 2014 10:45 PM
Snow Leopard File Vault Question and Basic System Password Question & Time Machine? GordonGekko999 Mac Basics and Help 0 Oct 25, 2013 07:06 AM
Imac secondary monitor question creeker79 Mac Basics and Help 0 Apr 22, 2013 04:31 PM
2012 13" MBA Secondary Monitor Fullscreen question danistyping MacBook Air 6 Mar 11, 2013 09:38 AM

Forum Jump

All times are GMT -5. The time now is 10:06 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC