Fwd: Need help with document, window controllers and bindings.
Fwd: Need help with document, window controllers and bindings.
- Subject: Fwd: Need help with document, window controllers and bindings.
- From: Lon Giese <email@hidden>
- Date: Tue, 16 May 2006 00:26:03 -0700
oops! I just noticed an error in the code below
in the UniverseDocument
-(void)save:(UniverseObjectClass *) universeObject
sender:(NSWindowController *)aController
{
[universeArray addObject:universeObject];
[aController reloadData];
}
should be
in the UniverseDocument
//If your universeObject is complex then you want the document to have
more control over it than in this simple example
// by passing each attribute to the documant rather than the whole
object
// if the universeObject was edited then you need to replace it
instead of adding it of course
-(void)save:(UniverseObjectClass *)universeObject
{
[universeArray addObject:universeObject];
NSArray *controllers = [self windowControllers];
//universeController was made first so it is at index 0
NSWindowController * universeController = [controllers
objectAtIndex:0];
[universeController reloadData];
}
Begin forwarded message:
From: Lon Giese <email@hidden>
Date: May 15, 2006 11:51:56 PM PDT
To: email@hidden
Subject: Re: Need help with document, window controllers and bindings.
The problem is, I don't know how to link all the objects involved.
This is what I am thinking:
1) An NSMutableArray object should live in my UniverseDocument object.
2) The save button in the design nib should call the save action
method located in the DesignWindowController.
3) The save action method should send the underlying data to the
UniverseDocument to be added to the mutable array there.
4) The design window should close.
5) The table control in the universe nib should be updated to show
the new record that was just added to the mutable array.
Dont release the DesignWindowController when the user saves, that's
not mac like. The user should decide when to close.
Dont pass the save through UniverseWindowController, go directly to
the document.
I never use bindings for tables, its simple enough to do it the old
fashion data source way. So i cant help you with the bindings.
Here's how I would do it:
in the DesignWindowController.
-(IBAction)save
{
[[self document] save:universeObject]; //[self document] returns
your UniverseDocument
}
in the UniverseDocument
-(void)save:(UniverseObjectClass *) universeObject
sender:(NSWindowController *)aController
{
[universeArray addObject:universeObject];
[aController reloadData];
}
-(void) windowDidLoad
{
//initialize whatever needs to be initialized to prepare to be a data
source
}
in the UniverseWindowController
-(void)windowDidLoad
{
[[self document] windowDidLoad];
[universeTable setDataSource:[self document]];
}
-(void)reloadData
{
[universeTable reloadData]
}
On May 15, 2006, at 10:06 PM, Nelson Santos wrote:
Hi all,
I'm stuck and I can't seem to think my way out of it. Can anyone
help?
Classes info:
A) My app has an NSDocument subclass named UniverseDocument. It
implements makeWindowControllers which sets up one window controller.
B) My app also has an NSWindowController subclass named
UniverseWindowController. This is the window controller that is
added to the document's window controllers mentioned in (A).
C) My app also has another NSWindowController subclass named
DesignWindowController. This window controller is instantiated and
added to the documents window controllers when the user clicks on a
button located in the window controller mentioned in (B).
How app works:
My app basically works like this: It is a multiple document program.
Upon loading, the UniverseWindowController loads a nib file which
consists of a window, a large NSTableView and an add button. When
the user clicks on the add button, the DesignWindowController gets
instantiated and loads and displays the Design nib. The user inputs
the data into the design nib. When the user clicks on the save
button in the nib, the design window closes and it is supposed to add
a new record to the table control in the universe window.
My problem:
The problem is, I don't know how to link all the objects involved.
This is what I am thinking:
1) An NSMutableArray object should live in my UniverseDocument object.
2) The save button in the design nib should call the save action
method located in the DesignWindowController.
3) The save action method should send the underlying data to the
UniverseDocument to be added to the mutable array there.
4) The design window should close.
5) The table control in the universe nib should be updated to show
the new record that was just added to the mutable array.
Numbers 1, 2 and 4 are no brainers. How do I get 3 and 5 working?
What's confusing me:
i) I tried to add an array controller to the Universe nib, but I
don't know how to bind it to the mutable array located in my
UniverseDocument.
ii) I can add a new object to the mutable array in the document
object from the save method in the DesignWindowController easily
enough, but I don't know how to make the table control reflect the
updated data set.
iii) Should I instantiate an NSMutableArray in the Universe nib? I
figure no, because the data should exist in my model object
(UniverseDocument).
iv) I don't want to have the mutable array object living in the
UniverseWindowController object, because it really should live in the
UniverseDocument object.
Getting dizzy... Help!
Thanks!
Nelson
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden