简体   繁体   English

如何获取NSTextField动态添加到NSMutableArray的值?

[英]How to get value of NSTextField dynamic add to NSMutableArray?

I have a Combobox contains 30 items (1,2,...,30). 我有一个组合框,其中包含30个项目(1、2,...,30)。 I want to select item in Combobox, create dynamic NSTextField same item selected in Combobox. 我想在组合框中选择项目,在组合框中选择创建相同项目的动态NSTextField。 Then user input text to NSTextField, and then click on button to get all text of each NSTextField add to NSMutableArray. 然后用户将文本输入到NSTextField,然后单击按钮以将每个NSTextField的所有文本添加到NSMutableArray。 I use bellow code to get text from NSTextField and add it to Array but it can only get from 1 NSTextField: 我使用下面的代码从NSTextField中获取文本并将其添加到Array中,但它只能从1个NSTextField中获取:

NSMutableArray * SSID_Arr = [[NSMutableArray alloc] initWithCapacity:x];
[SSID_Arr addObject:ssidtxt.stringValue]; // get text from NSTextField
NSLog (@"SSID_Arr : %@",SSID_Arr);

NSString *strSSID;
for(int j=0; j < [SSID_Arr count]; j++)
{
    strSSID = [NSString stringWithFormat:@"\r\nSSID : %@", [SSID_Arr objectAtIndex:j]];
}

Do you have suggestion? 你有建议吗? Thanks in advance 提前致谢

只是使

NSMutableArray *SSID_Arr = [NSMutableArray new];
NSMutableArray * SSID_Arr = [[NSMutableArray alloc] initWithCapacity:x];

gives an array with space reserved for x values.But there is no value in that position right now 给出一个为x 保留空间的数组, 但是现在该位置没有值

So first fill up the array via a loop and then continue as 因此,首先通过循环填充数组,然后继续

NSMutableArray * SSID_Arr = [[NSMutableArray alloc] initWithCapacity:x];
for (int i=0; i<x; i++) {
    [SSID_Arr addObject:ssidtxt.stringValue]; 
}

Now the array contains x values and you can proceed.Please note the one textfield value is getting populated here x times.If you have to store all textfield values ,write a loop suitable to achieve all values and add it 现在该数组包含x个值,您可以继续。请注意,这里一次填充了一个textfield值x次。如果必须存储所有textfield值,请编写一个适合于实现所有值的循环并将其添加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM