Ios 使用Segue返回TabBarController的初始ViewController后,TabBar将隐藏

Ios 使用Segue返回TabBarController的初始ViewController后,TabBar将隐藏,ios,swift,uitabbarcontroller,segue,uitabbar,Ios,Swift,Uitabbarcontroller,Segue,Uitabbar,我有一个带有三个表视图控制器的选项卡栏控制器,第二个VC嵌入到导航控制器中。在第二个VC中,我使用这一行self.tabBarController?.tabBar.ishiden=true隐藏了tabBar,并创建了一个bar按钮返回到第一个视图控制器,即使用segue with modal presentation的“主”VC 我的问题是,在按下“上一步”按钮并从第二个VC返回主VC后,尽管我将self.tabBarController?.tabBar.ishiden=false放在主VC的

我有一个带有三个表视图控制器的选项卡栏控制器,第二个VC嵌入到导航控制器中。在第二个VC中,我使用这一行
self.tabBarController?.tabBar.ishiden=true
隐藏了tabBar,并创建了一个bar按钮返回到第一个视图控制器,即使用segue with modal presentation的“主”VC

我的问题是,在按下“上一步”按钮并从第二个VC返回主VC后,尽管我将
self.tabBarController?.tabBar.ishiden=false
放在主VC的ViewWillAspect方法和第二个VC的ViewWillEnglishe方法中,但选项卡栏仍然隐藏

这是我预期的结果和我得到的结果


如何使选项卡栏显示?

当您使用模态演示序列时,您正在创建HomeViewController的全新实例。新的HomeViewController未链接到层次结构中的TabBarController

以下是初始视图层次结构:

TabBarController
 -> HomeVC
 -> CreateVC (Navigation Controller)
    -> CreateQuizVC
 -> SavedVC
现在,点击后退按钮后,您将看到以下内容:

TabBarController
 -> HomeVC
 -> CreateVC (Navigation Controller)
   -> CreateQuizVC
     -> HomeVC(2)
 -> SavedVC
您可以做的是,不使用segue返回,而是在代码中添加iAction,以编程方式设置选项卡栏的selectedIndex,并将back UIBarButtonim链接到此iAction

@IBAction func backButtonAction(_ backButton: UIBarButtonItem) {
    // Keep in mind that the CreateQuizVC is embeded in a NavigationController.
    // The NavigationController is the child of the TabBarController
    navigationController?.tabBarController?.selectedIndex = 0
    navigationController?.tabBarController?.tabBar.isHidden = false
}
然而,我的建议是,你可以按照苹果的意图使用TabBar。演示CreateQuizVC时不要隐藏它,使用选项卡栏在选项卡之间导航。这将有助于用户体验,因为iOS上的每个人都希望从选项卡栏中看到这种行为