0

I have a Navigation Controller (NC) and three ViewControllers (A, B, C) with the following navigation pattern:

NC->A->B->C

If I go from A to C and 'back' both B and C deinit method gets called.

If I use an Unwind Segue to go from C to A, B deinit does not get called.

Not clear why - I have another similar sequence in my App and deinits get called regardless of 'back' or 'unwind' operation.

Any idea what could cause B to 'stay alive' post an unwind operation?

zevij
  • 2,416
  • 1
  • 23
  • 32
  • 2
    Check to see if you have any strong reference cycles with that controller. Any repeating timers? Any non-`weak` delegate references? Any properties that are closures that reference `self` (but neglected to specify `weak` or `unowned self`)? Etc. – Rob Jun 27 '16 at 10:31
  • The problematic view is a simple UTTableViewController with a SearchController. On viewWillDisappear I set the SearchController as active = false, searchResultsUpdater = nil and remove it from parent view. There are no closures. other delegates that I add. The closest I get is to assign a local reference to the navigation controller but it is set back to nil as soon as I am done with it. – zevij Jun 27 '16 at 10:54

1 Answers1

1

Found the issue. The problem is this line I had in viewDidLoad:

definesPresentationContext = true

From the docs: Determines which parent view controller's view should be presented over for presentations of type UIModalPresentationCurrentContext. If no ancestor view controller has this flag set, then the presenter will be the root view controller.

As a result, the middle view (i.e. 'B') becomes the root unless it is dismissed by a 'back' operation.

To avoid having the search box still visible for a split second on view C, I added searchController.active = false in prepareForSegue of view B after I obtain the chosen value from user selection (tap on row).

zevij
  • 2,416
  • 1
  • 23
  • 32