实现texFiled代理方法
- ( BOOL )textField:( UITextField *)textField shouldChangeCharactersInRange:( NSRange )range replacementString:( NSString *)string
{ // 删除按钮
if (!string.length) return YES;
// 如果输入不是纯数字,不显示
if( ![self isPureInt:string]) return NO;
return YES;
}
判断NSString是否为纯数字
- (BOOL)isPureInt:(NSString*)string{
NSScanner* scan = [NSScanner scannerWithString:string];
int val;
return[scan scanInt:&val] && [scan isAtEnd];
}