Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 387
Deepak Avatar asked Sep 07 '12 13:09

Deepak


People also ask

How do I get IndexPath from cell Swift?

add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.

What is IndexPath in Tableview Swift?

Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section.


1 Answers

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];
like image 158
skywinder Avatar answered Sep 21 '22 05:09

skywinder