views:

752

answers:

2

indexPath.row returns null in tableView didSelectRowAtIndexPath:indexPath

I thought it was supposed to return the row selected.

When i look at indexPath in the debugger it (corectly) returns: "2 indexes [0, 0]"

Am I missing something?

+2  A: 

Well null is 0. The row property is type int -- perhaps you're mistakenly using it as an object or pointer.

You mention that you want the actual "row" that was selected. If you mean you want the cell that was selected, here's how:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

Note that if you somehow programmatically select a row that's not currently visible, this will return nil.

Daniel Dickison
I was using the wrong array access method :-S
pingbat
A: 

It returns the PATH to the row selected, not the row (or cell) itself.

indexPath(0,0) is the first cell of the first section. Depending on your test you are running, this may be the correct result.

mmc