0

I have an app that used to work before I upgraded to XCODE 5. I needed to find the row that was selected for a structure I was displaying which has over 100 rows so obviously can be scrolled on the display. The code that used to work is:

NSIndexPath *indexPath = [self.mainTableView indexPathForCell:myCell];
NSInteger row = [indexPath row];

Now, regardless of the row selected, the value of row is always 0. Anyone have any suggestions for me? Thanks.

Rick
  • 49
  • 13

2 Answers2

0

This worked for me...

CGPoint pos = [pressedButton convertPoint:CGPointZero toView:self.mainTableView];
NSIndexPath *indexPath = [self.mainTableView indexPathForRowAtPoint:pos];
NSInteger row = [indexPath row];

Rick
  • 49
  • 13
0

Remember that in Objective-C, you can always send a message nil, and methods that return something (i.e., not void) will return either nil(for an object) or 0 (for a value) when sent to nil (for structs, it is more complicated; read this).

So make sure that:

  1. self.mainTableView is not nil
  2. indexPath is not nil
Community
  • 1
  • 1
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189