2009-05-19 38 views
1

我有一個接口,有大量的控件,見下圖。高效地訪問衆多的可可控件

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

什麼是訪問這些的最佳途徑,創造了我的AppController類288 IBOutlets並將它們鏈接起來都顯得效率低下。

我看着表格,但他們似乎很簡單。

這是一個概念驗證,不會出貨,所以我打開任何想法。然而,我必須使用Objective-C作爲最終產品的一個警告將寫在Objective-C/Cocoa中。

NB:

  1. 接口是靜態
  2. 小盒裝將於整數(0-255)

回答

3

NSTableView看起來像您需要的UI。視覺渲染將有點不同,但它會看起來更'Mac'。

6

你應該看看NSMatrix。這正是它旨在解決的問題。

2

無論是NSMatrix,作爲羅布建議,或重新考慮UI所以你有它較少的控制:-)

0

您可以以編程方式構建整個接口,用代碼在一個循環中的幾行:

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); 
}