ios检查UITextfield.text的数值是否大于52

时间:2014-09-15 08:13:42

标签: ios objective-c uitextfield numeric maxlength

我正忙着弄清楚如何检测UITextfield文本的数值是否大于52?

我尝试使用NSScanner但没有运气。

NSScanner * scanner = [NSScanner scannerWithString:self.repeatOccurrenceFrequencyWeeklyTF.text];
    double val;
    [scanner scanDouble:&val];
    // Scanned the whole string and ended up with a positive value
    if( [scanner isAtEnd] && val > 52 ){
        NSLog(@"'%@'? I accept.", self.repeatOccurrenceFrequencyWeeklyTF.text);
    }
    else {
        NSLog(@"'%@' is no good.", self.repeatOccurrenceFrequencyWeeklyTF.text);
        [self showMessage:@"Week Error" Message:@"The week field must be filled in."];
    }

1 个答案:

答案 0 :(得分:3)

您可以将texField转换为int这样的值:
int changeid = [idchoice.text intValue];
将此int值与52

进行比较后