Hello all,

Thanks for your previous help. I'm trying to firm up my understanding of NSPopupButton. I wrote a test project modeled after Kevin Wojniak's example here:

http://forums.macrumors.com/showthread.php?p=4839485 , post #7, referencing matt neuburg's example.

One NSPopupButton
One NSArrayController (popupController)
One NSObject (popup) whose Class is set to "Popup"

You know how everyone always says "All I am trying to do is..." ? Well, I just want to get the popup's selection in my Model so I can use the value in my code.

Bindings:
PopupButton bound to NSArrayController "popupController":
Content: popupController.arrangedObjects.type
Content Values: popupController.arrangedObjects.type
Selected Object: popup.selectedType

Bindings for popupController:
Content: popup.gameTypes

The little bit of code is below. Two classes, although I don't understand why Kevin made the second class (my class "GameType").

PROBLEM: The popup is loaded from the model array through the controller. No problem. When I call my "changeArray" method, though, the popup's display adds a fourth element, which isn't in the actual model array. The model object "selectedType" correctly updates when the popup's selection is changed.

- Do I need this extra class and this loop that populates the array "gameTypes?" It works, and just binding the controller to the "popupArray" by itself does not work. I don't get this.

- Is instantiating the NSObject "popup" in IB and setting its class to the class in which my ivars are declared the correct way to provide the controller layer with access to the Model layer?

Thanks


//Popup.h***************************
#import <Cocoa/Cocoa.h>
@interface Popup : NSObject
{
//Make an NSString instance variable and and two arrays for the popup
        NSMutableArray *gameTypes;
        NSArray *popupArray;
        NSString *selectedType;
}
- (void) changeArray;
@property (readwrite, copy) NSArray *popupArray;
@property (readwrite, retain) NSMutableArray *gameTypes;
@property (readwrite, copy) NSString *selectedType;
@end

//Popup.m*************************
#import "GameType.h"
@implementation Popup: NSObject
@synthesize popupArray, gameTypes, selectedType;
- (id) init
{
        self = [super init];
        return self;
}
- (void) awakeFromNib
{
[self setPopupArray: [NSArray arrayWithObjects:@"C9", @"F11", @"Other", nil]];
        gameTypes = [NSMutableArray array];
        for (NSString *theType in popupArray)
        {
                GameType *gameTypeObject = [[[GameType alloc] init] 
autorelease];
                gameTypeObject.type = theType;
                [gameTypes addObject:gameTypeObject];
        }
        self.gameTypes = gameTypes;
}

- (void) changeArray //From the "method" binding of an NSButton in the nib file
{
self.selectedType=@"Deathy"; //This adds a fourth item to the popup's list, rather than renaming the selected item.
}
@end

//  GameType.h**********************
//  TestPopup

#import <Cocoa/Cocoa.h>
@interface GameType : NSObject
{
        NSString *type;
}
@property (readwrite, retain) NSString *type;
@end

//  GameType.m *********************
//  TestPopup
#import "GameType.h"
@implementation GameType
@synthesize type;
@end
_______________________________________________

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