An array of NSViews in Cocoa?

I am working on a Mac application. One of the windows can load several NSView objects that are in the same NIB / XIB file.

But my code looks like this:

@interface TheWindowController : NSWindowController {
    //Interface objects
    IBOutlet NSTableView    *detailsTree;
    IBOutlet NSView         *bigView;
    IBOutlet NSView         *subView1;
    IBOutlet NSView         *subView2;
    IBOutlet NSView         *subView3;
    IBOutlet NSView         *subView4;
    IBOutlet NSView         *subView5;
}

My question is, can all of these IBOutlets be held inside an array, dictionary, or something similar. So in the future, I could do something like this in my implementation:

- (IBAction)traceTableViewClick:(id)sender {
    //having now a NSArray called subviewsArray
    [[[bigView subviews] objectAtIndex:0] removeFromSuperview];
    [rightView addSubview: [subviewsArray objectAtIndex:[detailsTree selectedRow]]];
}

Is it possible? How? Any examples?

+3
source share
2 answers

- , , . @interface, IBOutlet Interface Builder, init NSArray :

- (id)init
{
    self = [super init];
    if (self != nil)
    {
        _viewArray = [[NSArray alloc] initWithObjects:subView1, subView2,
                        subView3, subView4, subView5, nil];
    }
    return self;
}

- (void)dealloc
{
    [_viewArray release];
    ...etc...
    [super dealloc];
}

:

- (void)doThing
{
    for (id view in _viewArray)
    {
        [view doSomething];
    }
}
0

NSView NS (Mutable) Array NS (Mutable) Dictionary , .

0

All Articles