NSInternalInconsistencyException in thread with no app code

I'm getting an internal inconsistency exception (Cannot call setItems:animated: directly on a UINavigationBar managed by a controller.) in a thread with no app code.

The stack trace suggests something to do with a context menu, but my app doesn't use any. I'm seeing a lot of crash reports, but I can't repro it myself, and no customers have reported it yet so I only have the stack trace (below) to go from.

It sure looks like a problem in UIKitCore.

CoreFoundation
__exceptionPreprocess
libobjc.A.dylib
objc_exception_throw
CoreFoundation
+[NSException raise:format:]
UIKitCore
-[UINavigationBar setItems:animated:]
UIKitCore
-[_UINavigationBarVisualProviderModernIOS _popToItem:]
UIKitCore
-[UIAction _performActionWithSender:]
UIKitCore
-[UIContextMenuInteraction _contextMenuPresentationController:didSelectMenuLeaf:]
UIKitCore
-[_UIClickPresentationInteraction _handleDidTransitionToPossibleFromState:context:]
UIKitCore
-[_UIRapidClickPresentationAssistant dismissWithReason:alongsideActions:completion:]
UIKitCore
-[_UIRapidClickPresentationAssistant _animateDismissalWithReason:actions:completion:]
UIKitCore
-[_UIRapidClickPresentationAssistant dismissWithReason:alongsideActions:completion:]
UIKitCore
stateMachineSpec_block_invoke_4
UIKitCore
handleEvent
UIKitCore
-[_UIClickPresentationInteraction _cancelWithReason:alongsideActions:completion:]
UIKitCore
-[UIContextMenuInteraction _contextMenuPresentationControllerWantsToBeDismissed:withReason:alongsideActions:completion:]
UIKitCore
-[_UIContextMenuPresentationController contextMenuView:didSelectElement:]
UIKitCore
-[_UIContextMenuView _performActionForElement:]
UIKitCore
-[_UIContextMenuView _handleSelectionForElement:]
UIKitCore
-[_UIContextMenuView _handleSelectionGesture:]
UIKitCore
-[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:]
UIKitCore
_UIGestureRecognizerSendTargetActions
UIKitCore
_UIGestureRecognizerSendActions
UIKitCore
-[UIGestureRecognizer _updateGestureForActiveEvents]
UIKitCore
_UIGestureEnvironmentUpdate
UIKitCore
-[UIGestureEnvironment _updateForEvent:window:]
UIKitCore
-[UIWindow sendEvent:]
UIKitCore
-[UIApplication sendEvent:]
UIKitCore
__dispatchPreprocessedEventFromEventQueue
UIKitCore
__processEventQueue
UIKitCore
__eventFetcherSourceCallback
CoreFoundation
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
CoreFoundation
__CFRunLoopDoSource0
CoreFoundation
__CFRunLoopDoSources0
CoreFoundation
__CFRunLoopRun
CoreFoundation
CFRunLoopRunSpecific
GraphicsServices
GSEventRunModal
UIKitCore
-[UIApplication _run]
UIKitCore
UIApplicationMain

The only way I can see this happen is if the navigation bar's delegate was changed, but the navigation bar is still owned by a UINavigationController. If you did change the delegate, thats likely to have broken a fair number of expected behaviors in such a case, including this one.

Thanks for the tip. That's exactly what I'm doing, and I just found the documentation that warns against this.

On this page, it says:

A navigation controller automatically assigns itself as the delegate of its navigation bar object. Therefore, when using a navigation controller, don’t assign a custom delegate object to the corresponding navigation bar.

There are places where I need to pop multiple levels off the nav bar stack, so I was pointing the delegate at my view controller and implementing shouldPopItem to add an extra "pop" where needed. I'll have to figure out a different way to achieve this.

NSInternalInconsistencyException in thread with no app code
 
 
Q