[baseten-users] How to use a single BXDatabaseContext object with multiple nib files

Tuukka Norri tuukka.norri at karppinen.fi
Mon May 25 16:07:27 EEST 2009


Hi!

Réjean Lamy kirjoitti 24.5.2009 kello 18.48:
> My application main window had tables with the BX Array Controllers  
> and buttons to load the other nibs, so yes, when a nib is loaded,  
> the context is already connected.
> I realize we can't pass an already connected context to a new nib  
> and use it with the nib's BX Array Controllers, right ?
This is possible by setting BXSynchronizedArrayController's Database  
Context binding (not the outlet) or by calling its - 
setDatabaseContext: method. We changed the fetching behaviour so that  
if the context is already connected, the array controller can be set  
to fetch automatically and not just on connect.

> I experimented with making the connection to context only when the  
> nib finish loading and it works. At this instant, all the BX Array  
> Controllers both on the main window and the nib works correctly. But  
> this is not the desired behavior. I need the main window working  
> with its  BX Array Controllers connected to the context and, only on  
> demand, loading a nib and passing the already connected context to  
> this nib.
>
> How can I handle this situation ?


Here's some sample code (may contain errors as I just wrote it). In  
your auxiliary nib, set the file's owner's class to NibOwner and bind  
the array controller's Database Context binding to it with  
“databaseContext” as the key path.

// Owner of Other.nib
@interface NibOwner : NSWindowController
{
	BXDatabaseContext* mContext;
}
@property (readwrite, retain) BXDatabaseContext* databaseContext;
@end


@implementation NibOwner
@synthesize databaseContext = mContext;
//-dealloc missing for the sake of clarity.
@end


// A controller class to be instantiated in your MainMenu.nib
@interface Controller : NSObject
{
	IBOutlet BXDatabaseContext* mContext;
}
- (void) instantiateNib;
@end


@implementation Controller
- (void) instantiateNib
{
	NibOwner* windowController = [[[NibOwner alloc]  
initWithWindowNibName: @"Other"] autorelease];
	//Add windowController to a collection or whatever.
	
	[windowController setDatabaseContext: mContext];
}
@end

-- 
Best regards,
Tuukka Norri
MK&C



More information about the baseten-users mailing list