giuseppe giuseppe - 10 months ago 53
iOS Question

Get the row of UITextField inside UITableViewCell

I have two

inside a custom cell of a
I need to edit and store values of the textFields.
When I click inside a
I have to know the row it belongs to in order to save the value to the correct record of a local array.
How can I get the row index of the textField?
I tried :

-(void)textFieldDidBeginEditing:(UITextField *)textField

currentRow = [self.tableView indexPathForSelectedRow].row;


But the currentRow does not change when I click inside the UITextFieldRow.It changes only when I click (select) the entire row...

Answer Source

Try this

//For ios 7

UITableViewCell *cell =(UITableViewCell *) textField.superview.superview.superview;
NSIndexPath *indexPath = [tblView indexPathForCell:cell];

//For ios 6

UITableViewCell *cell =(UITableViewCell *) textField.superview.superview;
NSIndexPath *indexPath = [tblView indexPathForCell:cell];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download