OrderDiscountViewController.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // OrderDiscountViewController.m
  3. // iSales-CONTRAST
  4. //
  5. // Created by Rui Zhang on 7/5/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OrderDiscountViewController.h"
  9. #define NUMBERS @"0123456789\n"
  10. @interface OrderDiscountViewController ()
  11. @end
  12. @implementation OrderDiscountViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. }
  17. /*
  18. #pragma mark - Navigation
  19. // In a storyboard-based application, you will often want to do a little preparation before navigation
  20. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  21. // Get the new view controller using [segue destinationViewController].
  22. // Pass the selected object to the new view controller.
  23. }
  24. */
  25. - (IBAction)onUpdate:(id)sender {
  26. [self dismissViewControllerAnimated:NO
  27. completion:^{
  28. if(self.onSetValue)
  29. self.onSetValue( [self.textfieldDiscount.text intValue]);
  30. }];
  31. }
  32. - (IBAction)onCancel:(id)sender {
  33. [self dismissViewControllerAnimated:NO
  34. completion:^{
  35. }];
  36. }
  37. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  38. // DebugLog(@"text:%@",textField.text);
  39. NSCharacterSet *cs;
  40. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
  41. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
  42. BOOL canChange = [string isEqualToString:filtered];
  43. return canChange;
  44. }
  45. @end