Iphone 从UITableviewCell获取视图对象的步骤
我在我的tableview中的单元格oe中添加了一个文本字段。 现在我想比较触摸的对象是否为textfield。为此,我使用-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单元格的文本字段中触摸视图。 我怎么能得到这个?我对这一
-(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现在,您将在主控制器中收到
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
}
}