- (BOOL)checkForDigits {
NSString *editableExpression = self.expression.text;
for (int i = 0; i < editableExpression.length; i++){
char charAtPosition = [editableExpression characterAtIndex:i];
for (int c = 0; c < 10; c++ ){
char digitAtPosition = digits[c];
if (charAtPosition == digitAtPosition){
return TRUE;
}
else {
return FALSE;
}
}
}
}
一直返回False不知道為什麼。
我用了isNaN方法但是沒有用,於是我自己做了isNaN。數字列陣:
char digits[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
- (BOOL)checkForDigits {
char digits[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
BOOL result;
NSString *editableExpression = @"dsjkdjk12lkv";
for (int i = 0; i < editableExpression.length; i++){
char charAtPosition = [editableExpression characterAtIndex:i];
for (int c = 0; c < 10; c++ ){
char digitAtPosition = digits[c];
if (charAtPosition == digitAtPosition){
NSLog(@"true");
return TRUE;
}
else {
result = FALSE;
}
}
}
return result;
}