實現(xiàn)texFiled代理方法
- ( BOOL )textField:( UITextField *)textField shouldChangeCharactersInRange:( NSRange )range replacementString:( NSString *)string
{ // 刪除按鈕
if (!string.length) return YES;
// 如果輸入不是純數(shù)字,不顯示
if( ![self isPureInt:string]) return NO;
return YES;
}
判斷NSString是否為純數(shù)字
- (BOOL)isPureInt:(NSString*)string{
NSScanner* scan = [NSScanner scannerWithString:string];
int val;
return[scan scanInt:&val] && [scan isAtEnd];
}