我在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
}