I have a RootViewController that is a UIViewController with a UITableView. This RootViewController pushes a ChildViewController based on the row selected. When I pop the ChildViewController and go back to the RootViewController, I want to be able to know the indexPath that was selected. Once I have the indexPath, I want to call the selectRowAtIndexPath:animated:scrollPosition: method to scroll that selected indexPath to the top.
I know how to grab the selected indexPath within the tableview (indexPathForSelectedRow) but I don’t know how to hold onto that value when I push the ChildViewController and then pop back to the RootViewController.
Add a field to your table view controller .h file:,
and then add
in your .m file. After that, store the value using
and then use it as follows: