方向更改后在 Unwind Segue 上崩溃
crash on Unwind Segue after orientation change
我有一个 unwind segue,在 iOS 9.3 上横向或纵向都可以正常工作,但是如果我在呈现目标视图控制器 (A) 和执行视图控制器之间旋转设备,则会抛出以下异常放松 (C).
知道为什么会发生这种情况,以及如何解决这个问题?
我的故事板的高级视图:
异常:
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
已解决。问题出在应用程序委托方法中:
func splitViewController(splitViewController: UISplitViewController,
collapseSecondaryViewController secondaryViewController: UIViewController,
ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
...
return true
}
此方法失败 return true,导致 splitViewController 在展开之前折叠目标视图控制器 (A),即 secondaryViewController。解决方案是通过 returning false 确保次级不会崩溃,从而确保展开的目标可用。
我有一个 unwind segue,在 iOS 9.3 上横向或纵向都可以正常工作,但是如果我在呈现目标视图控制器 (A) 和执行视图控制器之间旋转设备,则会抛出以下异常放松 (C).
知道为什么会发生这种情况,以及如何解决这个问题?
我的故事板的高级视图:
异常:
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
已解决。问题出在应用程序委托方法中:
func splitViewController(splitViewController: UISplitViewController,
collapseSecondaryViewController secondaryViewController: UIViewController,
ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
...
return true
}
此方法失败 return true,导致 splitViewController 在展开之前折叠目标视图控制器 (A),即 secondaryViewController。解决方案是通过 returning false 确保次级不会崩溃,从而确保展开的目标可用。