我在tabBarController上有5个项目,我只控制didSelect tabBar(索引1和索引3) . 当我点击索引3的项目时,ViewController显示成功,但是当我点击索引为1的项目时,我收到此错误:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 4]'

这是didSelect tabBar上的代码:

if item.tag == 1 {

         self.view.backgroundColor = .white
        let chatListController = ChatListViewController.viewControllerFromStoryborad(storyName: "Chat", viewName: "ChatList")

        let storyboard = UIStoryboard(name: "Main", bundle: nil)

        let navigation = storyboard.instantiateViewController(withIdentifier: "Chat_Navigation") as! UINavigationController

        navigation.pushViewController(chatListController, animated: true)
            self.viewControllers?[1] = navigation
            self.selectedIndex = 1
    }


    if item.tag == 3 {
        self.view.backgroundColor = .white
            let manageController = ManagingNormalViewController.viewControllerFromStoryborad(storyName: "Order", viewName: "Manage_Normal")

            let storyboard = UIStoryboard(name: "Main", bundle: nil)

            let navigation = storyboard.instantiateViewController(withIdentifier: "OrderNavigation") as! UINavigationController

            navigation.pushViewController(manageController, animated: true)
            self.viewControllers?[3] = navigation
            self.selectedIndex = 3

        }

为什么我收到此错误?!代码相同,数组索引正确 .
这是我的TabBarController的图像: