2014-01-30 33 views
1

嗨,我有UITableview單元格與文本字段我希望允許第二次觸摸鍵盤只有當文本字段出現第一次點擊它必須消失,第二次點擊它必須出現可以任何一個幫助我。這裏我附上我的示例代碼允許在UITableViewCell中的UITextField雙擊觸摸

======================================= ===========================================

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
[self.playerTable.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx,BOOL*stop) 
    { 
     UITableViewCell *cell = obj; 

     if([cell isKindOfClass:[UITableViewCell class]]) 
     { 
      for(UITextField *textField in cell.contentView.subviews) 
      { 
       if([textField isKindOfClass:[UITextField class]]) 
       { 
        if ([textField isFirstResponder]) 
        { 
         [textField resignFirstResponder]; 
        } 

       } 

      } 

     } 
    } ]; 

    return NO; 
} 
+1

和 - (BOOL)textFieldShouldReturn:(*的UITextField)文本框 { [文本字段resignFirstResponder]; return NO; } –

+0

在此先感謝任何人可以幫助我 –

+0

你的意思是雙擊(就像在textField上快速按兩下)? – santhu

回答

2

我已經得到解決我的問題

#pragma mark TextField methods 

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
[self.playerTable.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx,BOOL*stop) 
    {   UITableViewCell *cell = obj; 
        if([cell isKindOfClass:[UITableViewCell class]]) 
     {    for(UITextField *textField in cell.contentView.subviews) 
      {     if([textField isKindOfClass:[UITextField class]]) 
       {      if ([textField isFirstResponder]) 
        {       [textField resignFirstResponder]; 
              } 
             } 
           } 
         } 
       } ]; 
    return YES; 
} 
- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ int tapcount; tapCount = tapCount + 1; 
if (tapCount%2==0){  [textField becomeFirstResponder]; 
     [cursorView removeFromSuperview]; 
        tapCount = 0;  }else{ 
     {  [cursorView removeFromSuperview]; 
     [textField resignFirstResponder]; 
} 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ [textField resignFirstResponder]; 
    return NO; 
}