0

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!

  • What exactly are you trying to achieve here? – Adeel Miraj Oct 13 '15 at 18:47
  • i have label (for question label) and textfield(for answer textfield) inside tableviewcell, but i need to input text in textfield.. the problem is in my API should looping parameter ANSWER (this should in uitextfield), like ANSWER1 ANSWER2 ANSWER3, i already declare parameter ANSWER in my uitextfield but when i complite insert text in all looping uitextfield and klik OK, my parameter ANSWER still empty, because uitextfield dont know which one is ANSWER1 or ANSWER2 or ANSWER3, its should consecutive from top to end looping.. – Muhammad Yusuf Oct 13 '15 at 19:32
  • i want use tag , like i succes get indexpath my button before, like this self.button.tag=indexPath.row; but i dont how to get indexpath use tag with uitextfield – Muhammad Yusuf Oct 13 '15 at 19:34
  • See this previous post: http://stackoverflow.com/questions/12319058/how-to-get-cell-indexpath-in-uitextfield-delegate-methods – slebreton Aug 03 '16 at 08:22

2 Answers2

1

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];
} 
Arben Pnishi
  • 591
  • 5
  • 11
0

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

Adeel Miraj
  • 2,472
  • 3
  • 22
  • 32