FROM : Michael Babin
DATE : Tue May 20 20:30:33 2008
On May 20, 2008, at 9:41 AM, Johnny Lundy wrote:
> QUESTION: How would you implement the binding to the model objects
> "popUpArray" and "selectedGame" so that the popup loads from
> "popUpArray" and its selection is kept in sync with the property
> "selectedGame?" Specifically, is there a way to do it without
> instantiating the object PopUp in the nib file?
>
> I know how I have done it, and page 118 of Aaron's 3rd edition says
> the same, but I want to hear if there is a "pure" MVC-compliant way
> to do it.
If you want to bind your array controller to properties of Popup and
don't want to instantiate Popup in the nib, then create a path through
File Owner (or in the case of MainMenu.nib, the application delegate
object) to get the Popup object.
For example:
AppDelegate.h
@interface AppDelegate : NSObject {
Popup *popup;
}
@property (readonly) Popup *popup;
@end
AppDelegate.m
@implementation AppDelegate
@synthesize popup;
- (id) init
{
self = [super init];
if (self != nil) {
popup = [[Popup alloc] init];
}
return self;
}
@end
Change your Popup object to set-up your data in its init method,
rather than awakeFromNib (since it's no longer in a nib).
Then in your array controller, bind Content Array to the application
delegate with a model key path of "popup.popupArray". The same applies
to the array controller's selection (same as you would for Popup in
the nib, just bind to the application delegate with a model key path
starting with "popup".
The general point is to use a path through a controller to your model
object outside of the nib.
DATE : Tue May 20 20:30:33 2008
On May 20, 2008, at 9:41 AM, Johnny Lundy wrote:
> QUESTION: How would you implement the binding to the model objects
> "popUpArray" and "selectedGame" so that the popup loads from
> "popUpArray" and its selection is kept in sync with the property
> "selectedGame?" Specifically, is there a way to do it without
> instantiating the object PopUp in the nib file?
>
> I know how I have done it, and page 118 of Aaron's 3rd edition says
> the same, but I want to hear if there is a "pure" MVC-compliant way
> to do it.
If you want to bind your array controller to properties of Popup and
don't want to instantiate Popup in the nib, then create a path through
File Owner (or in the case of MainMenu.nib, the application delegate
object) to get the Popup object.
For example:
AppDelegate.h
@interface AppDelegate : NSObject {
Popup *popup;
}
@property (readonly) Popup *popup;
@end
AppDelegate.m
@implementation AppDelegate
@synthesize popup;
- (id) init
{
self = [super init];
if (self != nil) {
popup = [[Popup alloc] init];
}
return self;
}
@end
Change your Popup object to set-up your data in its init method,
rather than awakeFromNib (since it's no longer in a nib).
Then in your array controller, bind Content Array to the application
delegate with a model key path of "popup.popupArray". The same applies
to the array controller's selection (same as you would for Popup in
the nib, just bind to the application delegate with a model key path
starting with "popup".
The general point is to use a path through a controller to your model
object outside of the nib.
| Related mails | Author | Date |
|---|---|---|
| Johnny Lundy | May 20, 16:41 | |
| Erik Buck | May 20, 19:42 | |
| Michael Babin | May 20, 20:30 |






Cocoa mail archive

