I would like to use an NSBox *dynamicSection to replace the content of the box with a different view depending on the index selected from and NSPopUpButton control. The method below receives the NSPopUPButton as an object, and uses a case switch to dynamically set the view and title for the box.
@interface AppDelegate : NSObject <NSApplicationDelegate> {
IBOutlet NSTextField *dynamicTitle;
NSMutableString *title;
NSBox *dynamicSection;
NSView *Sect1_View;
NSView *Sect2_View;
NSView *Sect3a_View;
NSView *Sect3b_View;
NSView *Sect3c_View;
NSView *Sect4_View;
}
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSBox *dynamicSection;
@property (assign) IBOutlet NSPopUpButton *menuOptions;
}
@implementation {
- (IBAction)menuSelected:(NSPopUpButton *)sender {
NSInteger index = [sender indexOfSelectedItem];
NSLog(@"Selected button index is %ld", index);
switch (index) {
case 0:
dynamicSection = [[NSBox alloc] init];
[dynamicSection setTitle:[self returnSectionTitle:index]];
[dynamicSection setContentView:Sect1_View];
NSLog(@"%@",[self returnSectionTitle:index]);
break;
case 1:
dynamicSection = [[NSBox alloc] init];
[dynamicSection setTitle:[self returnSectionTitle:index]];
[dynamicSection setContentView:Sect2_View];
break;
case 2:
dynamicSection = [[NSBox alloc] init];
[dynamicSection setTitle:[self returnSectionTitle:index]];
[dynamicSection setContentView:Sect3a_View];
break;
case 3:
dynamicSection = [[NSBox alloc] init];
[dynamicSection setTitle:[self returnSectionTitle:index]];
[dynamicSection setContentView:Sect3b_View];
break;
case 4:
dynamicSection = [[NSBox alloc] init];
[dynamicSection setTitle:[self returnSectionTitle:index]];
[dynamicSection setContentView:Sect3c_View];
break;
case 5:
dynamicSection = [[NSBox alloc] init];
[dynamicSection setTitle:[self returnSectionTitle:index]];
[dynamicSection setContentView:Sect4_View];
break;
default:
break;
}
}
}
It is recognizing the correct index, and printing the title to the log, however it does not correctly switch the view upon selection. Any suggestions?
Thanks!