Custom View with Interface Builder Bindings
Custom View with Interface Builder Bindings
- Subject: Custom View with Interface Builder Bindings
- From: Richard Somers <email@hidden>
- Date: Mon, 3 Jan 2011 09:27:28 -0700
I have a custom view in a Nib. The view programmatically creates a
bunch of "objects" during initialization. These "objects" depend upon
the document managed object context. Currently the "objects" are
created in 'awakeFromNib'. It all works fine.
@implementation MyCustomView
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self) {
// Currently do nothing here.
}
return self;
}
- (void)awakeFromNib
{
// Create a bunch of "objects" programmatically which
// depend on the document managed object context (which
// is reachable at this stage of initialization).
}
@end
I would like to establish bindings in Interface Builder between the
"objects" created by the custom view and some standard Interface
Builder widgets. The problem is 'awakeFromNib' is called AFTER the
bindings are established so the bindings never work.
Nib loading order.
1. Load contents of Nib.
2. Custom view receives 'initWithFrame:'.
3. Establish outlets, action connections, and bindings.
4. Custom view receives 'awakeFromNib'.
The problem would be solved if the "objects" were created in
'initWithFrame:' which happens BEFORE the bindings are established.
But I can find no way to obtain the document managed object context in
'initWithFrame:' because the window controller of the view is nil at
this stage of initialization.
The Nib is loaded by a custom document window controller. The document
managed object context is valid before the window controller is even
allocated or initialized. But I can find no way to get this
information to the custom view.
@implementation MyDocument
- (void)makeWindowControllers
{
// document managed object context is valid
MyDocumentWindowController *windowController;
windowController = [[MyDocumentWindowController alloc] init];
[self addWindowController:windowController];
[windowController release];
}
@end
Any suggestions? Thanks.
--Richard Somers
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden