Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIControlEventTouchDown不适用于UIScrollView_Ios_Objective C_Uiscrollview_Uitextfield_Uicontrolevents - Fatal编程技术网

Ios UIControlEventTouchDown不适用于UIScrollView

Ios UIControlEventTouchDown不适用于UIScrollView,ios,objective-c,uiscrollview,uitextfield,uicontrolevents,Ios,Objective C,Uiscrollview,Uitextfield,Uicontrolevents,我有以下代码,当用户单击我的文本字段并调用函数时,这些代码会捕获: -(void)viewDidLoad{ [mytextfield addTarget:self action:@selector(callvariant:) forControlEvents:UIControlEventTouchDown]; } -(void)callvariant:(UITextField *)textField{ Novo

我有以下代码,当用户单击我的文本字段并调用函数时,这些代码会捕获:

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

        }
现在,当用户单击文本字段时,有时调用函数,有时不调用,而在其他时间,需要将文本字段向下单击2秒以上才能调用函数,有时此方法不起作用


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

如果您想捕获用户触摸UITextField的事件,最好使用其委托方法

UITextFieldDelegat有一个方法

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.
如果您在此处执行某些操作并返回“否”,您将得到相同的结果