I am having trouble trying to update the values in an NSPopupButton programatically....
I can set it up just fine, in awakeFromNib, all the connections work as they should - I just can't redraw the items in the popupbutton.
Am I missing something?
I dropped an nspopupbutton into my project in xcode, connected it up to the cssButton Outlet.
heres my code:
my.h
my.m
this is nuts....
I can set it up just fine, in awakeFromNib, all the connections work as they should - I just can't redraw the items in the popupbutton.
Am I missing something?
I dropped an nspopupbutton into my project in xcode, connected it up to the cssButton Outlet.
heres my code:
my.h
Code:
@interface myPreferences : NSPreferencesModule <NSPreferencesModule>
{
IBOutlet NSPopUpButton *CSSButton;
}
- (void)reloadCSSButton:(NSString *)cssName;
@property (retain) NSPopUpButton *CSSButton;
my.m
Code:
@implementation myPreferences
@synthesize CSSButton
- (void) awakeFromNib
{
//get User StyleSheet Name and load ccsButton
NSString* cssFilePath = [[NSUserDefaults standardUserDefaults] stringForKey:styleSheetLocation];
cssFilePath = [cssFilePath stringByExpandingTildeInPath];
NSString* cssName = [cssFilePath lastPathComponent];
[self reloadCSSButton:cssName];
}
//this works fine when called in awakeFromNib, but not elsewhere?
- (void)reloadCSSButton:(NSString *)cssName
{
[CSSButton removeAllItems];
if (cssName != nil) {
[CSSButton addItemWithTitle:[NSString stringWithFormat:@"%@", cssName]];
[[CSSButton menu] addItem:[NSMenuItem separatorItem]];
[CSSButton addItemWithTitle:@"None Selected"];
[CSSButton addItemWithTitle:@"Other..."];
[CSSButton setAction: @selector(addCSS:)];
[CSSButton selectItemAtIndex:0];
[CSSButton setTarget:self];
}
else {
[CSSButton addItemWithTitle:@"None Selected"];
[CSSButton addItemWithTitle:@"Other..."];
[CSSButton setAction: @selector(addCSS:)];
[CSSButton selectItemAtIndex:0];
[CSSButton setTarget:self];
}
}
//this works fine
-(IBOutlet)addCSS:(id)sender
{
if ([sender titleOfSelectedItem] == @"Other...")
{
................unrelated code.....................
}
if ([sender titleOfSelectedItem] == @"None Selected")
{
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:styleSheetLocation];
[[NSUserDefaults standardUserDefaults] synchronize];
//this call doesn't work, ie I am trying to redraw the popupbutton with out the separatorItem or the item:cssName......
[self reloadCSSButton:nil];
........... unrelated code.........................
}
}
this is nuts....