Search code examples
iphoneobjective-cuitableviewuser-interfaceuitextfield

How to get cell indexpath in uitextfield Delegate Methods?


I have two textfields in a custom cell how to get the indexpath value of Tableview cell in textfield delegate methods I want to get the input value from user and save it to the relavent object. the user can add more cells by clicking button(Add More) in cell..

enter image description here

Thanks in Advance...


Solution

  • Update to iOS7!

    With new features in iOS7 now code should be :

    UITableViewCell *textFieldRowCell;
    
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
        // Load resources for iOS 6.1 or earlier
        textFieldRowCell = (UITableViewCell *) textField.superview.superview;
    
    } else {
        // Load resources for iOS 7 or later
        textFieldRowCell = (UITableViewCell *) textField.superview.superview.superview; 
       // TextField -> UITableVieCellContentView -> (in iOS 7!)ScrollView -> Whoola!
    }
    
    NSIndexPath *indexPath = [self.tableView indexPathForCell:textFieldRowCell];