如何将触摸事件从UITextField转发到UICollectionViewController / UITableViewController?

时间:2014-10-21 12:29:59

标签: ios uitableview uitextfield uicollectionview

我有cell,上面有UITextField。 TextField在整个单元格中拉伸 。当我按下textField键盘时,但didSelectItemAtIndexPath将不会被调用。

我该如何触发它? didSelectItemAtIndexPath发送所选单元格indexPath。我需要它。

2 个答案:

答案 0 :(得分:1)

就个人而言,我会以相反的方式做到这一点......

cell.textfield.userInteractionEnabled = NO;

然后在didSelectRowAtIndexPath

MYTextFieldCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell.textfield becomeFirstResponder];
cell.textfield.userInteractionEnabled = YES;

// code that needs the indexPath

订阅UITextFieldTextDidEndEditingNotification并设置

textfield.userInteractionEnabled = NO; 

当你完成时

答案 1 :(得分:0)

首先在forCellAtIndexPath方法中添加标签到uitextfield

  UITextField *txtField=[[UITextField alloc]initWithFrame:CGRectMake(0,0,self.view.width,self.view.height)];
     txtField.tag=indexPath.row;
txtField.delegate=self;
    [cell addSubview:txtField];

关于textFieldDidBeginEditing的第二个 现在,您可以通过检查textField的标记

来获取单元格的索引路径
NSLog(@"IndexPath ....%li",(unsigned long)textField.tag);