开发者

How do you put an integer array into a setIntValue in objective-c?

开发者 https://www.devze.com 2023-02-25 04:59 出处:网络
I have: myAnswerArray[i] with four-digit integers stored in them like, 开发者_JS百科myAnswerArray[0]=1412

I have:

myAnswerArray[i] with four-digit integers stored in them like,

开发者_JS百科myAnswerArray[0]=1412
myAnswerArray[1]=0518
myAnswerArray[2]=2307

I have an IBOutlet 'answerField'

so I want to [answerField setIntValue:(something)]

and have it send:

1412 0518 2307 to the text field.


For a small array:

[answerField setStringValue:[NSString stringWithFormat:@"%04i %04i %04i", myAnswerArray[0], myAnswerArray[1], myAnswerArray[2]]];

For larger array, build your string using NSMutableString:

NSMutableString *temp = [NSMutableString stringWithCapacity:500];
for (int i = 0; i < 100; i++) {
    [temp appendFormat:@"%04i ", myAnswerArray[i]];
}

[answerField setStringValue:temp];


Try:

[answerField setStringValue:[myAnswerArray componentsJoinedByString:@" "]];
0

精彩评论

暂无评论...
验证码 换一张
取 消