NSPopupButtons work, but not in hierarchical mode, what am I missing here ?
NSPopupButtons work, but not in hierarchical mode, what am I missing here ?
- Subject: NSPopupButtons work, but not in hierarchical mode, what am I missing here ?
- From: Bill Hernandez <email@hidden>
- Date: Fri, 7 May 2010 11:02:23 -0500
Hi everybody,
I have a hierarchical popup button that should allow me to select a row and column, both at the same time instead of having to use one popup menu for row, and one for column
If for example, I select (row, col) = (4,2) as shown, as soon as the mouse is released the selected item goes back to (row, col) = (1,1) which is what was checked in IB.
[ 1 ]
[ 2 ]
[ 3 ] [ 1 ]
[ 4 ] > [ 2 ]
[ 5 ] [ 3 ]
[ 6 ] [ 4 ]
[ 7 ] [ 5 ]
[ 8 ] [ 6 ]
[ 7 ]
[ 8 ]
The regular (non hierMenus) popup buttons work great, the Action Methods trigger correctly, and the window is redrawn with the correct number of rows and columns.
If you get a chance to look at it, the project download is at :
http://www.journey-of-flight.com/bh_xcode/how-to/0150_Drawing_in_Views/index.php
TIA,
Bill Hernandez
Plano, Texas
http://www.journey-of-flight.com
// MainView.h
@interface MainView : NSView
{
// +---------+---------+---------+---------+---------+---------+---------+---------+
// Declare the instance variables
// +---------+---------+---------+---------+---------+---------+---------+---------+
IBOutlet NSPopUpButton *aRows;
IBOutlet NSPopUpButton *aColumns;
IBOutlet NSPopUpButton *aRowCols; // hierarchical popup button
}
// +---------+---------+---------+---------+---------+---------+---------+---------+
// Declare the instance variable properties, so accessor methods are generated
// +---------+---------+---------+---------+---------+---------+---------+---------+
// @property (nonatomic, retain) IBOutlet NSPopUpButton *aRowCols;
// @property (nonatomic, retain) IBOutlet NSPopUpButton *aRows;
// @property (nonatomic, retain) IBOutlet NSPopUpButton *aColumns;
// +---------+---------+---------+---------+---------+---------+---------+---------+
// ACTION METHODS
// +---------+---------+---------+---------+---------+---------+---------+---------+
- (IBAction)selectRowsPopupMenu:(id)sender;
- (IBAction)selectColumnsPopupMenu:(id)sender;
- (IBAction)selectRowAndColumnPopupMenu:(id) sender;
// +---------+---------+---------+---------+---------+---------+---------+---------+
@end
// MainView.m
#import "MainView.h"
static NSUInteger noOfBoxes = 3; // These created a problem when defined as iVars,
static NSUInteger noOfRows = 2; // and one of the popup menu selections changed
// +---------+---------+---------+---------+---------+---------+---------+---------+
// IMPLEMENTATION
// +---------+---------+---------+---------+---------+---------+---------+---------+
@implementation MainView
// @synthesize aRowCols;
// @synthesize aRows;
// @synthesize aColumns;
// +---------+---------+---------+---------+---------+---------+---------+---------+
#pragma mark -
#pragma mark Action Routines - Popup Menus
#pragma mark -
// +---------+---------+---------+---------+---------+---------+---------+---------+
- (IBAction) selectRowAndColumnPopupMenu:(id) sender
{
// NSMenu *projectMenu = [sender menu];
// NSLog(@"projectMenu = %@", projectMenu);
// NSUInteger *menuValue = [[sender titleOfSelectedItem] intValue];
NSUInteger *menuValue = [sender indexOfSelectedItem];
NSLog(@"[4301] menuValue %d", menuValue);
NSMenuItem *menuItem = [sender selectedItem];
NSLog(@"menuItem %@", menuItem);
NSLog(@"hasSubMenu %d", [menuItem hasSubmenu]);
NSMenu *subMenu = [menuItem submenu];
NSLog(@"submenu %@", subMenu);
// NSUInteger *subMenuValue = [[subMenu titleOfSelectedItem] intValue];
// NSLog(@"[4302] subMenuValue %d", subMenuValue);
}
// +---------+---------+---------+---------+---------+---------+---------+---------+
- (IBAction)selectRowsPopupMenu:(id)sender
{
noOfRows = [[aRows titleOfSelectedItem] intValue];
NSLog(@"[4807] -(IBAction)selectRowsPopupMenu:(id)sender --> %d", noOfRows);
[mainView setNeedsDisplay:YES]; // Invalidate the mainView area, so it will get redrawn
}
// +---------+---------+---------+---------+---------+---------+---------+---------+
- (IBAction)selectColumnsPopupMenu:(id)sender
{
noOfBoxes = [[aColumns titleOfSelectedItem] intValue];
NSLog(@"[4808] -(IBAction)selectColumnsPopupMenu:(id)sender --> %d", noOfBoxes);
[mainView setNeedsDisplay:YES]; // Invalidate the mainView area, so it will get redrawn
}
// +---------+---------+---------+---------+---------+---------+---------+---------+
// +---------+---------+---------+---------+---------+---------+---------+---------+
- (void)awakeFromNib
{
// I don't try to set the hierMenu here, I am just accepting what I set in IB
// it would be great to be able to set the (row, col) dynamically here as well
[aRows selectItemWithTitle:[NSString stringWithFormat:@"%d", noOfRows]];
[aRows synchronizeTitleAndSelectedItem];
[aColumns selectItemWithTitle:[NSString stringWithFormat:@"%d", noOfBoxes]];
[aColumns synchronizeTitleAndSelectedItem];
}
// +---------+---------+---------+---------+---------+---------+---------+---------+
@end
_______________________________________________
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