title: Get IndexPath.Row from TableView Objective C
body: <p>Before asking this question, I searched a lot on Google and Stackoverflow. Tried also some examples, but I can't make the function work.</p>
  
  <p>Since the hierarchy of the tableview is changed since iOS 7, is it kind of hard to find a solution.</p>
  
  <p>I got a standard tableview with a couple items and one button on the screen.</p>
  
  <p>I need to get the indexPath.row number when selecting an item from the tableview and clicking on the button.</p>
  
  <p>This is my code</p>
  
  <pre><code>- (IBAction)buttonGetNumber:(id)sender {
  
      NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[(UIView *)[button superview] superview]];
      NSLog(@"%i", indexPath.row);
  }
  </code></pre>
  
  <p>This keeps returning a '0', no matter which item I select from the tableview.</p>
  
  <p>I also tried this (2):</p>
  
  <pre><code>- (IBAction)buttonGetNumber:(id)sender {
      UIButton *button = (UIButton *)sender;
      UITableViewCell *cell = (UITableViewCell *) [[button superview] superview];
      NSIndexPath *index = [self.tableView indexPathForCell:cell];
      NSLog(@"%i", index.row);
  }
  </code></pre>
  
  <p>This also returns a '0'.</p>
  
  <p>I also tried this (3):</p>
  
  <pre><code>- (IBAction)buttonGetNumber:(id)sender {
      UIButton *senderButton = (UIButton *)sender;
      UITableViewCell *buttonCell = (UITableViewCell *)[[senderButton superview] superview];
      UITableView* table = (UITableView *)[buttonCell superview];
      NSIndexPath* pathOfTheCell = [table indexPathForCell:buttonCell];
      NSInteger rowOfTheCell = [pathOfTheCell row];
      NSLog(@"%i", rowOfTheCell);
  }
  </code></pre>
  
  <p>And this makes the application crash.</p>
  
  <p>Any clue how I can solve this?</p>
  
  <p><img src="https://i.stack.imgur.com/Q7TgC.png" alt="enter image description here"></p>