2012-03-14 4 views
2

UITableView私はUIButton(セルのサブビューとして)を配置しています。また、テーブルの下には、UITextFieldがあります。 textFieldに触れると、キーパッドはいつものように表示されます。私が望むのは、テーブルに触れることでキーパッドを却下することです。UITableView onTouch hideキーパッド

私が考えたオプションは、UITableViewの場合はUITapGestureRecognizerと設定していました。しかし、私はtableCell上にボタンがあるとそのアイデアを投げつけてしまい、それが応答しなくなりました。

また、キーパッドに完了または戻るボタンを表示したくありません。私が言いたいことは、キーパッドがキーパッドから消えてしまうのではなく、それが持っているボタンを見ながらテーブルに触れることです。

+0

これを確認してください。 http://stackoverflow.com/a/6370673/641062 – Vignesh

答えて

4

お試しください。

//NSnotification when keyboard is shown 
- (void)keyboardWasShown:(NSNotification *)notification 
{  
    // Get the size of the keyboard. 
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone){ 

     if(UIInterfaceOrientationPortrait==orientation || UIInterfaceOrientationPortraitUpsideDown==orientation){ 
      keyboardSize=CGSizeMake(320.000000, 216.000000); 
     } 
    else if(UIInterfaceOrientationLandscapeLeft==orientation || UIInterfaceOrientationLandscapeRight==orientation) 
     { 
      keyboardSize=CGSizeMake(162.000000, 480.000000); 
     } 
    } 
    else if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){ 
     if(UIInterfaceOrientationPortrait==orientation || UIInterfaceOrientationPortraitUpsideDown==orientation) 
      keyboardSize=CGSizeMake(768.000000, 264.000000);   

     else if(UIInterfaceOrientationLandscapeLeft==orientation || UIInterfaceOrientationLandscapeRight==orientation) 
     { 
      keyboardSize=CGSizeMake(352.000000,1024.000000); 

     } 
    } 

    // Adjust the bottom content inset of your scroll view by the keyboard height. 
    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0); 
    scrvwLogig.contentInset = contentInsets; 
    scrvwLogig.scrollIndicatorInsets = contentInsets; 

    // Scroll the target text field into view. 
    CGRect aRect = self.view.frame; 
    aRect.size.height -= keyboardSize.height; 
    if (!CGRectContainsPoint(aRect, txtpassword.frame.origin)) { 

     CGPoint scrollPoint=CGPointZero; 
     //check flag for iPhone orientation 
     if(flgLandScape)   
      scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y-70); 
     //check flag for iPhone/iPad orientation 
     else if(flgPort || flgPortiPad) 
      scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y - (keyboardSize.height-50));   
     //check flag for ipad orientation 
     else if(flgLandScapeiPad)   
      scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y-130); 

     [scrvwLogig setContentOffset:scrollPoint animated:YES]; 
    } 
} 


//when keyboard is hide 

- (void) keyboardWillHide:(NSNotification *)notification { 

    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
    scrvwLogig.contentInset = contentInsets; 
    scrvwLogig.scrollIndicatorInsets = contentInsets; 
} 
+0

同様のコードatleast私と一緒に働く! :) –

+0

+1 :-)コードの良い説明のために。 –

0

UIView(OR UIButton)を使用することもできます。キーボードが表示される前に、透明なUIView(320x480)を追加し、そのビューのタッチイベントでキーボードを非表示にして、ビューを削除することができます。

+0

次にテーブルはどのようにスクロールしますか? – Nitish

+0

@Nitish:hmm true ...スクロールするかタッチするときにキーボードを隠したいのですか? – Maulik

+0

@Nitish:テーブルのスクロールでキーボードが隠れる場合もあります。 – Maulik