2010-05-21 30 views
2

我想在我的應用程序中實現NSForm視圖,我是cocoas應用程序中的新成員。可以向我諮詢有關此控制器的信息嗎?如何在可可應用程序中實現NSForm?

+0

+1我從來沒有注意到'NSForm'前... – 2010-05-21 14:06:36

回答

4

你可以在你的應用程序中使用NSForm。

  1. 在您榫文件中添加NSForm
  2. 通過編程創建NSForm並附加NSform在你的窗口視圖。

@ 2我這裏有一個例子,使用它可以理解

NSWindow*window  = [self window]; // gets current widnow 
NSView *theContentView = [window contentView]; // gets view from window 

NSRect contentRect = [theContentView frame]; // gets frame from view 

NSRect formRect = NSMakeRect(0, 50, 300, 220); // creates new frame 

NSForm *theForm; 
theForm = [[NSForm alloc] initWithFrame:formRect]; // init with frame fromRect 

NSFormCell *theFormCell; // create cell for form 

// defines first cell with field First Name 
theFormCell = [theForm addEntry:@"First Name:"]; 
[theFormCell setTag:EContactFieldTag_FirstName]; 

// defines first cell with field Last Name 
theFormCell = [theForm addEntry:@"Last Name:"]; 
[theFormCell setTag:EContactFieldTag_LastName]; 

[theForm setCellSize:NSMakeSize(300, 25)]; // defines size for cell 
[theForm sizeToCells]; 

[theForm setKeyCell:theFormCell]; // assign cell to form 

[theContentView addSubview:theForm]; // add form to current view 

我想這應該幫助您開始。

讓我知道如果您有任何問題。

+0

是感謝其工作fine.Now我想在一個陣列中得到NSFormcell值怎麼可能呢? – mikw 2010-05-21 11:35:58

+0

您可以創建一個數組並循環遍歷它,並讓您創建單元格,如 NSInteger i = 0; for(id * item in array_data){ theFormCell = [theForm addEntry:(NSString *)item]; [theFormCell setStringValue:[[NSString alloc] initWithFormat:@「%d」,i]]; [theFormCell setTag:i]; //爲所有nscell提供標記差異\t i ++; } 這將爲數組中的所有項目生成單元格,並將i值放入其中。 – 2010-05-24 05:59:16

相關問題