TabBarController的ViewControllers数组索引返回NSRangeException

时间:2018-12-09 13:31:27

标签: ios swift uitabbarcontroller

我在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的图像: enter image description here

0 个答案:

没有答案