0

我有这段代码,当用户点击我的文本字段时,它会捕获并调用一个函数:

-(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];

    }

该代码完美运行,但最近需要使用以下代码在我的项目中放置一个 UIScrollView:

-(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];

        }

现在有时候当用户点击textfield时调用函数,有时候不调用,而其他时候需要保持text field点击2秒以上才能调用函数,有时候这个方法不起作用。

我不知道会发生什么,但我该如何解决这个问题?

4

1 回答 1

0

如果你想捕捉用户触摸 UITextField 的事件,你最好使用它的委托方法。

UITextFieldDelegate 有一个方法

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

如果你在这里做某事并返回 NO,你会得到相同的结果。

于 2014-07-09T00:31:22.147 回答