Effectively Accessing Numerous Cocoa Controls

I have an interface with a lot of controls, see the image below.

Interface http://www.richardstelling.com/hosted/cocoainterface.png

What is the best way to access them by creating 288s IBOutlets

in my class AppController

and linking them all together seems inefficient.

I looked at the shapes, but they seemed simplistic.

This is a proof of concept and will not ship, so I am open to any ideas. One caveat, however, is that I have to use Objective-C as the final product will be written in Objective-C / Cocoa.

Note:

  • The interface is static
  • The smaller box will contain integers (0-255)
+1


a source to share


4 answers


The NSTableView looks like the UI you want. The visual rendering will be slightly different, but it will look more "Mac".



+3


a source


You should have a look at NSMatrix . This is exactly what he decided to solve.



+6


a source


Either NSMatrix

as Rob suggests, or changed your mind about the interface so you have fewer controls :-)

+2


a source


You can completely program the entire interface with a few lines of code in a loop:

const int numRows = 11;
const int rowWidth = 400;
const int rowHeight = 20;
const int itemSpacing = 5;
const int nameFieldWidth = 120;
const int smallFieldWidth = 30;

NSMutableArray * rowList = [[NSMutableArray alloc] initWithCapacity:numRows];

int rowIndex;
NSRect rowFrame = [controlView bounds];
rowFrame.origin.y = rowFrame.size.height - rowHeight;
rowFrame.size.height = rowHeight;
NSRect itemRect
for (rowIndex = 0; rowIndex < 11; rowIndex++)
{
    // create a new controller for the current row
    MyRowController * rowController = [[MyRowController alloc] init];
    [rowList addObject:rowController];
    [rowController release];

    // create and link the checkbox
    itemRect = rowFrame;
    itemRect.size.width = 20;
    NSButton * checkBox = [[NSButton alloc] initWithFrame:itemRect];
    [controlView addSubview:checkBox];
    [rowController setCheckBox:checkBox];
    [checkBox release];

    // create and link the name field
    itemRect.origin.x += itemRect.size.width + itemSpacing;
    itemRect.size.width = nameFieldWidth;
    NSTextField * nameField = [[NSTextField alloc] initWithFrame:itemRect];
    [controlView addSubview:nameField];
    [rowController setNameField:nameField];
    [nameField release];

    // create and link the smaller fields
    itemRect.origin.x += itemRect.size.width + itemSpacing;
    itemRect.size.width = smallFieldWidth;
    NSTextField * smallField_1 = [[NSTextField alloc] initWithFrame:itemRect];
    [controlView addSubview:smallField_1];
    [rowController setSmallField_1:smallField_1];
    [smallField_1 release];

    //.. continue for each item in a row ..

    // increment the main rectangle for the next loop
    rowFrame.origin.y -= (rowFrame.size.height + itemSpacing);
}

      

0


a source







All Articles