giuseppe giuseppe - 5 months ago 32
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];