How to pass an Index Path to another table

Say you have a central array somewhere and would like display this in more detail via two table view controllers. Instead of passing only the relevant information, you want to pass the entire index path from table1 to table2 and beyond.

You can pass data in the prepareForSegue:sender method and let the Storyboard to the heavy lifting:

Here we instantiate a new Table2 object on which myIndexPath is a property. Then we set it to our own table’s selected indexPath. In Table2 we can then pick it up and read out the array’s property.

Note that the didSelectRowAtIndexPath method of the table view can be completely empty for the data to be passed on. In fact, should you try an pass data in this method it won’t be available until the table is drawn.

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.