0

I have this code, who capture when the user click in my textfield, and call a function:

-(void)viewDidLoad{
    [mytextfield addTarget:self
                  action:@selector(callvariant:)
        forControlEvents:UIControlEventTouchDown];
    }
-(void)callvariant:(UITextField *)textField{

        NovoProdutoMFViewController *mf = [[NovoProdutoMFViewController alloc] init];
        [self.navigationController pushViewController:mf animated:YES];

        [mf setBusca:textField.placeholder];

    }

The code works perfectly, but recently had the need to put a UIScrollView in my project with this code:

-(void)viewDidLoad{
        [mytextfield addTarget:self
                      action:@selector(callvariant:)
            forControlEvents:UIControlEventTouchDown];

    scroll.contentSize = scroll.frame.size;
    scroll.frame = self.view.frame;

    [self.view addSubview:scroll];
        }
-(void)callvariant:(UITextField *)textField{

            NovoProdutoMFViewController *mf = [[NovoProdutoMFViewController alloc] init];
            [self.navigationController pushViewController:mf animated:YES];

            [mf setBusca:textField.placeholder];

        }

Now Sometimes when the user click on textfield call the function and sometimes not call, and at other times it is necessary to keep the text field clicked down for more than 2 seconds to call the function and has sometimes this method does not work.

I do not know what might be happening, but how can I solve this?

user3781174
  • 245
  • 5
  • 16

1 Answers1

0

If you want to catch the event of user touch a UITextField, You better use its delegate method.

UITextFieldDelegat has a method

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.

if you do something here and return NO, you will get the same result.

Ryan
  • 4,799
  • 1
  • 29
  • 56