App crash: Inconsistency in UITabBar items and view controllers detected. No view controller matches the UITabBarItem.

Several users are seeing a crash in a new app version that introduces the use of a UITabBarController. We haven't been able to isolate the crash to a specific user flow, device, or OS version.

Fatal Exception: NSInternalInconsistencyException Inconsistency in UITabBar items and view controllers detected. No view controller matches the UITabBarItem '<UITabBarItem: 0x130623160> title='Today' image=<UIImage:0x3001893b0 named(RootTab-resources: today) {36, 32} renderingMode=automatic(original)> selected'.

0  CoreFoundation                 0x83f20 __exceptionPreprocess
1  libobjc.A.dylib                0x16018 objc_exception_throw
2  Foundation                     0x6de868 _userInfoForFileAndLine
3  UIKitCore                      0x85c9d8 -[UITabBarController _viewControllerForTabBarItem:]
4  UIKitCore                      0x85ca80 -[UITabBarController _tabBarItemClicked:]
5  UIKitCore                      0x3fb31c -[UIApplication sendAction:to:from:forEvent:]
6  UIKitCore                      0x785d18 -[UITabBar _sendAction:withEvent:]
7  UIKitCore                      0x3fb31c -[UIApplication sendAction:to:from:forEvent:]
8  UIKitCore                      0x3fb1f4 -[UIControl sendAction:to:forEvent:]
9  UIKitCore                      0x3fb044 -[UIControl _sendActionsForEvents:withEvent:]
10 UIKitCore                      0x787054 -[UITabBar _buttonUp:]
11 UIKitCore                      0x3fb31c -[UIApplication sendAction:to:from:forEvent:]
12 UIKitCore                      0x3fb1f4 -[UIControl sendAction:to:forEvent:]
13 UIKitCore                      0x3fb044 -[UIControl _sendActionsForEvents:withEvent:]
14 UIKitCore                      0x913894 -[UIControl touchesEnded:withEvent:]
15 UIKitCore                      0x33beac -[UIWindow _sendTouchesForEvent:]
16 UIKitCore                      0x33b954 -[UIWindow sendEvent:]
17 UIKitCore                      0x1bc9e0 -[UIApplication sendEvent:]
18 UIKitCore                      0x1be1d4 __dispatchPreprocessedEventFromEventQueue
19 UIKitCore                      0x1c6ecc __processEventQueue
20 UIKitCore                      0xb984c updateCycleEntry
21 UIKitCore                      0xb776c _UIUpdateSequenceRun
22 UIKitCore                      0xb73b0 schedulerStepScheduledMainSection
23 UIKitCore                      0xb8254 runloopSourceCallback
24 CoreFoundation                 0x56834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
25 CoreFoundation                 0x567c8 __CFRunLoopDoSource0
26 CoreFoundation                 0x54298 __CFRunLoopDoSources0
27 CoreFoundation                 0x53484 __CFRunLoopRun
28 CoreFoundation                 0x52cd8 CFRunLoopRunSpecific
29 GraphicsServices               0x11a8 GSEventRunModal
30 UIKitCore                      0x40a90c -[UIApplication _run]
31 UIKitCore                      0x4be9d0 UIApplicationMain
32 Coach                          0x62a44 main + 14 (main.m:14)
33 ???                            0x1bcfd9e4c (Missing)

I have only found 2 references to this exception online and neither of them have a resolution:

https://stackoverflow.com/questions/77536249/embed-flutterviewcontroller-to-native-swift-tabbar

https://github-com.translate.goog/ChenYilong/CYLTabBarController/issues/608?_x_tr_sl=zh-CN&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=sc

Any ideas on how this can be further investigated or resolved?

Answered by DTS Engineer in 795156022

Thanks for posting on the forums, it’s hard to know the issue just based on the crash without seeing the code. However, the error message you're encountering is a common issue in iOS development when there's a mismatch between the UITabBarItems in your tab bar and their corresponding UIViewControllers.

To resolve this issue, please go through the following steps to ensure a consistent relationship between UITabBarItems and UIViewControllers in your Xcode project:

  1. Check Your Tab Bar Controller Storyboard:

    • If you've set up your tab bar controller using a storyboard:
      • Ensure that your view controllers associated with tab bar items are designed correctly.
      • Select your tab bar controller in the storyboard navigator.
      • In the Attributes Inspector, check the 'Tab Bar Items' section. Make sure that the title, image, and other properties of each tab bar item match with the corresponding view controller you have set for it.
      if a tab bar item has no associated view controller in storyboards, the system will raise this exception.
  2. Refactor Your View Controller Code:

    • Go through your view controller classes (e.g., TodayViewController, assuming these are custom classes used for your view controllers).
    • Make sure you have correctly assigned yourself as the root view controller for each tab bar item.
  3. Assign Tab Bar Items to View Controllers Programmatically:

  • If you are programmatically setting up your tab bar controller, rather than using a storyboard.
    • In your AppDelegate.swift file, when creating the tab bar controller, assign the tab bar items to their corresponding view controllers.

  1. Recheck and Purge Derived Data:
    • Clean and build your project. Before that, delete the derived data folder.
    • Sometimes, Xcode's derived data can get corrupted, leading to such issues.

If none of the above steps resolve your problem, the next possibilities could be:

  1. You have mistakenly removed or reset the selection of one of the tab bar items in Interface Builder.
  2. The layout of your view controllers in the storyboard doesn't match the way you are creating them itinerary.

Always remember there should be a 1:1 relationship between tab bar items and viewport controllers, with each item associated with a valid view corresponding to its state.

Hope this helps resolving your issue. Otherwise, I would suggest to post a simple focused project that shows the issue.

Accepted Answer

Thanks for posting on the forums, it’s hard to know the issue just based on the crash without seeing the code. However, the error message you're encountering is a common issue in iOS development when there's a mismatch between the UITabBarItems in your tab bar and their corresponding UIViewControllers.

To resolve this issue, please go through the following steps to ensure a consistent relationship between UITabBarItems and UIViewControllers in your Xcode project:

  1. Check Your Tab Bar Controller Storyboard:

    • If you've set up your tab bar controller using a storyboard:
      • Ensure that your view controllers associated with tab bar items are designed correctly.
      • Select your tab bar controller in the storyboard navigator.
      • In the Attributes Inspector, check the 'Tab Bar Items' section. Make sure that the title, image, and other properties of each tab bar item match with the corresponding view controller you have set for it.
      if a tab bar item has no associated view controller in storyboards, the system will raise this exception.
  2. Refactor Your View Controller Code:

    • Go through your view controller classes (e.g., TodayViewController, assuming these are custom classes used for your view controllers).
    • Make sure you have correctly assigned yourself as the root view controller for each tab bar item.
  3. Assign Tab Bar Items to View Controllers Programmatically:

  • If you are programmatically setting up your tab bar controller, rather than using a storyboard.
    • In your AppDelegate.swift file, when creating the tab bar controller, assign the tab bar items to their corresponding view controllers.

  1. Recheck and Purge Derived Data:
    • Clean and build your project. Before that, delete the derived data folder.
    • Sometimes, Xcode's derived data can get corrupted, leading to such issues.

If none of the above steps resolve your problem, the next possibilities could be:

  1. You have mistakenly removed or reset the selection of one of the tab bar items in Interface Builder.
  2. The layout of your view controllers in the storyboard doesn't match the way you are creating them itinerary.

Always remember there should be a 1:1 relationship between tab bar items and viewport controllers, with each item associated with a valid view corresponding to its state.

Hope this helps resolving your issue. Otherwise, I would suggest to post a simple focused project that shows the issue.

Thanks for you response. The issue ended up being that we had mistakenly created 2 UITabBarController instances and moved the child viewcontrollers over to the one that wasn't being displayed. The crash occurred when a tab bar item was tapped and the associated viewcontroller was referencing the other UITabBarController instance.

App crash: Inconsistency in UITabBar items and view controllers detected. No view controller matches the UITabBarItem.
 
 
Q