In OS X, splitting a GUI into multiple NIB files and NSView subclasses

I am developing an OS X / Cocoa application and I need the following:

  • There is a sidebar with various options, such as "Option A", "Option B" and "Option C".
  • When you press A, B or C, it loads the corresponding GUI into the main panel. Each GUI is a different subclass of NSView and is defined in a different NIB / XIB file. For example, Option A can have 3 buttons and be an instance of NSViewSubclassA, while option B can have 1 button and a text field and be an instance of NSViewSubclassB.

How will I program this?

+3
source share
1

NSViewController, . , , nib ( ivar ). nib. , , , .

. ( ) ; - ( , ).

- (void)_setAccessoryViewControllerFromTag:(NSInteger)tag;
{
    if ( _accessoryContentViewController != nil )
    {
        [self setNextResponder:[_accessoryContentViewController nextResponder]];
        [_accessoryContentViewController release];
    }

    switch ( tag )
    {
        case 0:
            _accessoryContentViewController = [[RLGraphsViewController alloc] initWithNibName:@"GraphsView" bundle:nil];
            break;
        case 1:
            _accessoryContentViewController = [[RLSummaryViewController alloc] initWithNibName:@"SummaryView" bundle:nil];
            break;
        case 2:
            _accessoryContentViewController = [[RLEquipmentViewController alloc] initWithNibName:@"EquipmentView" bundle:nil];
            break;
        default:
            _accessoryContentViewController = [[RLLocationsViewController alloc] initWithNibName:@"LocationsView" bundle:nil];
            break;
    }

    [_accessoryContentViewController setNextResponder:[self nextResponder]];
    [self setNextResponder:_accessoryContentViewController];        
    [self.accessoryView setContentView:[_accessoryContentViewController view]];
}
+7

All Articles