Objective c 从textfield中获取多个整数值

Objective c 从textfield中获取多个整数值,objective-c,nstextfield,nsinteger,nsrange,Objective C,Nstextfield,Nsinteger,Nsrange,我想从文本字段中读取许多不同的整数值,为此,我有以下代码: NSString *string1,*string2; string1= [textField stringValue]; int i,c; c=0; NSInteger values[50]; for (i=0; i<50; ) { string2=[NSString stringWithFormat:@"%@%i%s",@" ",i,","]; NSRange range=[string1 rangeOfSt

我想从文本字段中读取许多不同的整数值,为此,我有以下代码:

NSString *string1,*string2;
string1= [textField stringValue];
int i,c;
c=0;
NSInteger values[50];
for (i=0; i<50; ) {
    string2=[NSString stringWithFormat:@"%@%i%s",@" ",i,","];

    NSRange range=[string1 rangeOfString:string2];

    if (range.location != NSNotFound) {
        values[c]=i;
        c=c+1;

    }
    i=i+1;
}
NSString*string1、*string2;
string1=[textField stringValue];
int i,c;
c=0;
NSInteger值[50];

对于(i=0;i如何改为:

NSArray *integerStrings = [[textField stringValue] componentsSeparatedByString:@","];

for (NSString *integerString in integerStrings) {
    NSDecimalNumber *number = [NSDecimalNumber decimalNumberWithString:integerString];

    // do whatever you want with the number...
}
或者,如果数字始终是整数,则循环可以是:

for (NSString *integerString in integerStrings) {
    NSInteger number = [integerString integerValue];

    // do whatever you want with the number...
}
看见