允许键盘在UITableViewCell中的UITextField上双击

时间:2014-01-30 07:12:32

标签: ios iphone objective-c uitableview

嗨我有UITableview单元格和文本字段我希望只允许键盘进行第二次触摸,如果第一次单击出现文本字段则必须消失,第二次点击它必须出现可以任何人帮助我。这里我附上了我的示例代码

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

- (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 个答案:

答案 0 :(得分: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;
}