-1

I have a table view which has cells in it. In each cell there is a button to take you to a new UITableView. I am trying to figure out how to get the index of the cell I clicked the button in from the new UITableView because depending on what cell index I choose it needs to show different items in the new UITableView it takes you to. Any help would be appreciated.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Quinn
  • 89
  • 2
  • 10

1 Answers1

0

set tag property of the button equal to the indexPath.row in cellForRowAtIndexPath method or in your custom cell class if you are using one.

Hence, when its clicked, you can get the value of indexPath.row from its tag (sender.tag).

Note: Assuming there is only one section in your tableview and you wont be inserting or deleting rows runtime. You will have to reload the table in such scenarios.

The best solution that I personally use is, to pass the cell a model object via property or custom method. And later, use the object to make further decisions.

Harshit Gupta
  • 1,200
  • 12
  • 27