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.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to