2014-07-08 44 views
0

我有這樣的代碼,誰抓住當用戶點擊我的文本框,並調用一個函數工作:UIControlEventTouchDown不UIScrollView的

-(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秒調用函數,有時這種方法不會工作。

我不知道會發生什麼,但我該如何解決這個問題?

回答

0

如果要捕捉用戶觸摸UITextField的事件,最好使用它的委託方法。

UITextFieldDelegat有一個方法

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

,如果你在這裏做一些事情,並返回NO,你會得到相同的結果。