Muhammad Yusuf
Muhammad Yusuf

Reputation: 11

how to get indexpath uitextfield inside tableviewcell?

i just know to get indexpath button inside tableviewcell like this

CGPoint center= [sender center]; CGPoint rootViewPoint = [[sender superview] convertPoint:center toView:_tableView1]; NSIndexPath *indexPath = [_tableView1 indexPathForRowAtPoint:rootViewPoint]; NSLog(@"%@",indexPath);

but i need know about textfield thx for helping me guys!

Upvotes: 0

Views: 579

Answers (2)

Arben Pnishi
Arben Pnishi

Reputation: 591

There is another method to get the index row!

In cellForRow do this:

textField.tag = indexPath.row;

In the textField method do this:

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    NSInteger row = textField.tag;    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
} 

Upvotes: 1

Adeel Miraj
Adeel Miraj

Reputation: 2496

To get the indexPath of the cell in which the textfield is contained you need to do a couple of things.

  1. Make the viewController class the delegate of the textField in the tableView's cell
  2. Implement textFieldDidBeginEditing method of textField's delegateProtocol in your viewController's class like this

- (void)textFieldDidBeginEditing:(UITextField *)textField { //Here you can you the same logic to find the indexPath of the cell like you use in case of a button. }

Upvotes: 0

Related Questions