Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从UITableviewCell获取视图对象的步骤_Iphone_Ios_Uitableview_Uitextfield - Fatal编程技术网

Iphone 从UITableviewCell获取视图对象的步骤

Iphone 从UITableviewCell获取视图对象的步骤,iphone,ios,uitableview,uitextfield,Iphone,Ios,Uitableview,Uitextfield,我在我的tableview中的单元格oe中添加了一个文本字段。 现在我想比较触摸的对象是否为textfield。为此,我使用- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event { UITouch *touch = [[event allTouches] anyObject]; } 方法。在这里,我必须在UITableview单元格的文本字段中触摸视图。 我怎么能得到这个?我对这一

我在我的tableview中的单元格oe中添加了一个文本字段。 现在我想比较触摸的对象是否为textfield。为此,我使用-

  -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event
    {
       UITouch *touch = [[event allTouches] anyObject];
    }
方法。在这里,我必须在UITableview单元格的文本字段中触摸视图。
我怎么能得到这个?我对这一点很感兴趣。请提供帮助。

使用TextField委托方法:

-(void)textFieldDidBeginEditing:(UITextField *)textField

我认为实现这一目标的最佳途径是:

  • 使用
    UITextField
    作为子视图创建一个
    UITableViewCell
    子类。将其定义为一个
    IBOutlet
    ,并通过interface builder将其连接起来
  • 创建委托协议以通知委托(在您的情况下,它可能是处理
    UITableViewDataSource
    )此事件的同一类)
  • UITableViewCell
    子类声明为
    UITextFieldDelegate
    ,并将其连接到您创建的
    UITextField
    。通过IB
  • 实施

    -(无效)textFieldDidBeginEditing:(UITextField*)textField{ [self.delegate textfield已点击]; }


  • 现在,您将在主控制器中收到
    textFieldWasTapped
    事件的通知。无需检查它是否确实来自UITextField对象,因为只有此类型的实例才能触发此调用。

    为什么要在ToucheSBegind:方法中获得触摸?为什么不使用outlet for textfield或uitextfield的委托方法?
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event
    {
        UITouch *touch = [[event allTouches] anyObject];
        if([[touch view] isKindOfClass:[UITextField class]])
        {
             UITextField *txtField = (UITextField *) [touch view];
             //UITextField object
        }
    }