在UITableViewCell
中,单元格中有多个uitextfield
,那么如何识别uitextfield
委托方法中除标签属性之外的哪个文本字段会产生动作?
Is your textfield is a member of a class? or created inside the method. If your textfield is a member variable you can check it by :
- (void) textFieldDidEndEditing:(UITextField *)textField
{
if ( [textfield isEqual:m_yourTextField] )
{
}
}
This way, you don't need to use tags. :D
您可以在cellForRowAtIndexPath:
分配特定文本字段的标记值cellForRowAtIndexPath:
例如分配indexPath.row)作为标记值,并将其条件放入uitextfield
委托方法中
Check the below code:
In your cellForRowAtIndexPath
[cell.yourtextField setTag:indexPath.row];
[cell.yourtextField addTarget:self action:@selector(textClicked:)
forControlEvents:UIControlEventTouchUpInside];
Then
-(void)textClicked:(UITextFiled*)txt
{
NSLog(@"viewbuttonClicked:%ld",(long int)[txt tag]);
}
- (void) textFieldDidEndEditing:(UITextField *)textField{
if (textField == _txtPhone) {
//Phone text field
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.