// // OrderDiscountViewController.m // iSales-CONTRAST // // Created by Rui Zhang on 7/5/22. // Copyright © 2022 United Software Applications, Inc. All rights reserved. // #import "OrderDiscountViewController.h" #import "RAUtils.h" #define NUMBERS @"0123456789\n" @interface OrderDiscountViewController () @end @implementation OrderDiscountViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ - (IBAction)onUpdate:(id)sender { if([self.textfieldDiscount.text intValue]>100) { [RAUtils message_box:@"Warrning" message:@"Illegal input" completion:nil]; return; } [self dismissViewControllerAnimated:NO completion:^{ if(self.onSetValue) self.onSetValue( [self.textfieldDiscount.text intValue]); }]; } - (IBAction)onCancel:(id)sender { [self dismissViewControllerAnimated:NO completion:^{ }]; } -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ // DebugLog(@"text:%@",textField.text); NSCharacterSet *cs; cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet]; NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; BOOL canChange = [string isEqualToString:filtered]; return canChange; } @end