Action on Pop


Rick Aurbach
 

iOS 13+, Xcode 11.4.1, Storyboard-based application.

I am using a navigation stack to manage some data edits. That is,
  • nav-controller root  is a list of items.
  • tap on item to segue to a detail panel to edit an item (which is a collection of subItems)
  • subItems may either be edited on the detail panel or
  • tap on a subItem to segue to a subDetail panel
        ... etc.

(Typically, this stack is three layers deep, but I'm looking for a solution that works for arbitrary depth.)

Now for all levels of this hierarchy, if the user taps the back button (or performs a gesture with same effect), I need to recognize this fact so that I can pass data up the hierarchy (hopefully without requiring strong coupling throughout).

The way I'm currently doing this is to execute a closure in each panel's deinit method. (Note that viewWillDisappear does not work except in the case of stack-depth == 2)). However putting this kind of code in deinit seems to me to be a code-smell.

Can you suggest an alternate that works at all levels of an arbitrarily deep navigation stack?

Rick Aurbach

Join {cocoa@apple-dev.groups.io to automatically receive all group messages.