1

I have an unwind segue which works fine in landscape or portrait on iOS 9.3, but throws the following exception if I rotate the device between presenting the target view controller (A) and the view controller performing the unwind (C).

Any ideas why this happens, and how to work around this problem?

A high level view of my storyboard:

enter image description here

The exception:

2016-03-28 16:58:14.194 ClarityLife[96444:11508887] *** Assertion failure in -[_UIStoryboardUnwindChain initFromSourceViewController:toDestinationViewController:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UIStoryboardUnwindSegueTemplate.m:119
2016-03-28 16:58:14.202 ClarityLife[96444:11508887] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not unwind from <ClarityLife.VideoCallDisconnectingViewController: 0x7fdaa07c2b50> to <ClarityLife.VideoCallIdleViewController: 0x7fdaa2c13ab0> because a common ancestor could not be found. (Note that it is not supported to unwind from a view controller to one of its descendants.)'
*** First throw call stack:
(
  0   CoreFoundation                      0x000000011128bd85 __exceptionPreprocess + 165
  1   libobjc.A.dylib                     0x0000000113f92deb objc_exception_throw + 48
  2   CoreFoundation                      0x000000011128bbea +[NSException raise:format:arguments:] + 106
  3   Foundation                          0x0000000111e93d5a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
  4   UIKit                               0x0000000113384c97 -[_UIStoryboardUnwindChain initFromSourceViewController:toDestinationViewController:] + 908
  5   UIKit                               0x0000000113385e49 -[UIStoryboardUnwindSegueTemplate newDefaultPerformHandlerForSegue:] + 125
  6   UIKit                               0x000000011315e395 -[UIStoryboardSegueTemplate segueWithDestinationViewController:] + 431
  7   UIKit                               0x00000001133865b7 -[UIStoryboardUnwindSegueTemplate segueWithDestinationViewController:] + 631
  8   UIKit                               0x00000001133868ae -[UIStoryboardUnwindSegueTemplate _performWithDestinationViewController:sender:] + 120
  9   UIKit                               0x0000000113386808 -[UIStoryboardUnwindSegueTemplate _perform:] + 86
  10  UIKit                               0x0000000112bb45f8 -[UIViewController performSegueWithIdentifier:sender:] + 99
  11  ClarityLife                         0x000000010fa6f9c5 _TFC11ClarityLife36VideoCallDisconnectingViewController13viewDidAppearfSbT_ + 261
  12  ClarityLife                         0x000000010fa6fa21 _TToFC11ClarityLife36VideoCallDisconnectingViewController13viewDidAppearfSbT_ + 49
  13  UIKit                               0x0000000112bb7335 -[UIViewController _setViewAppearState:isAnimating:] + 830
  14  UIKit                               0x0000000112bb7cb8 -[UIViewController _endAppearanceTransition:] + 262
  15  UIKit                               0x0000000112b8208a -[UIPresentationController transitionDidFinish:] + 827
  16  UIKit                               0x0000000112d5f38f -[_UICurrentContextPresentationController transitionDidFinish:] + 42
  17  UIKit                               0x0000000112b857c1 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
  18  UIKit                               0x00000001134444c8 -[_UIViewControllerTransitionContext completeTransition:] + 101
  19  UIKit                               0x0000000112b7ef77 -[UITransitionView notifyDidCompleteTransition:] + 252
  20  UIKit                               0x0000000112b7ec88 -[UITransitionView _didCompleteTransition:] + 1344
  21  UIKit                               0x0000000112b813f4 -[UITransitionView _transitionDidStop:finished:] + 104
  22  UIKit                               0x0000000112aa47ff -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 241
  23  UIKit                               0x0000000112aa4bae -[UIViewAnimationState animationDidStop:finished:] + 80
  24  QuartzCore                          0x00000001128c93c8 _ZN2CA5Layer23run_animation_callbacksEPv + 308
  25  libdispatch.dylib                   0x00000001160393eb _dispatch_client_callout + 8
  26  libdispatch.dylib                   0x00000001160211ef _dispatch_main_queue_callback_4CF + 1738
  27  CoreFoundation                      0x00000001111e50f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
  28  CoreFoundation                      0x00000001111a6b99 __CFRunLoopRun + 2073
  29  CoreFoundation                      0x00000001111a60f8 CFRunLoopRunSpecific + 488
  30  GraphicsServices                    0x0000000115ad5ad2 GSEventRunModal + 161
  31  UIKit                               0x0000000112a16f09 UIApplicationMain + 171
  32  ClarityLife                         0x000000010fa11432 main + 114
  33  libdyld.dylib                       0x000000011606d92d start + 1
  34  ???                                 0x0000000000000001 0x0 + 1
Joseph
  • 1,354
  • 12
  • 15

1 Answers1

5

Resolved. The problem is in the app delegate method:

func splitViewController(splitViewController: UISplitViewController,
  collapseSecondaryViewController secondaryViewController: UIViewController,
  ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
  ...
  return true
}

This method fell through to return true, which caused splitViewController to collapse the target view controller (A), which is the secondaryViewController, prior to the unwind. The solution is to ensure the secondary is not collapsed by returning false, thereby ensuring that the target of the unwind is available.

Joseph
  • 1,354
  • 12
  • 15