didSelectRowAtIndexPath returning a very large number

70 views Asked by At

Trying to find the row number touched in a TableViewController using:

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let indexPath = tableView.indexPathForSelectedRow();
    let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell?;
    NSLog("Current Cell = %d", currentCell!)
}

It returns the same number if you press the same cell but comes up with extremely large numbers like 410772272 or 409747056. In a two cell test I was expecting a 1 or 2. Returns the same numbers if you use a %i or %d.

Any insights or am I using the wrong call completely.

1

There are 1 answers

1
Glorfindel On BEST ANSWER

With

NSLog("Current Cell = %d", currentCell!)

you are printing the memory address which is stored in the currentCell variable - that is why it is such a high number.

You can get the row number via indexPath.row; you don't even need the let currentCell = line.