【发布时间】:2018-08-24 04:34:34
【问题描述】:
有一个带有多个 UIViewControllers 的 UITabBarController。在其中一个控制器中,当满足某个条件时,我想实例化另一个 UIViewController,它是同一个 UITabBarController 的子级。 我不断收到此错误“应用程序试图以模态方式呈现活动控制器”,但我不明白 scheduleNavController 是如何处于活动状态的。我在 SO 上查找了几个答案,但我仍然不明白我的错误是什么,我该如何解决? app的流程是这样的:WelcomeViewController,LoginViewController,UITabBarController和UITabBarController的children。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabController = storyboard.instantiateViewController(withIdentifier: "CentralTabBarControllerID") as! UITabBarController
if let viewControllers = tabBarController?.viewControllers {
let scheduleNavController = viewControllers[1] as! UINavigationController
let scheduleVC = scheduleNavController.childViewControllers[0] as! Schedule
tabController.present(scheduleNavController, animated: true, completion: {
scheduleVC.segmentedControlIndexReceivedFromClaimDetail = self.segmentedControlIndex
})
}
【问题讨论】:
-
您从活动视图控制器数组中检索
scheduleNavController,然后尝试以道德的方式呈现它。 -
@Paulw11 那我该怎么办?
-
为什么不简单地更改标签栏控制器的
selectedIndex? -
@AndreasOetjen 我已经使用了您建议的方法。但是,您能否在不使用
selectedIndex的情况下发布修复我原始问题中的代码的答案?我已经看到很多使用我在原始问题中尝试过的方法提出的问题。我认为这样的答案对其他 SO 成员会有所帮助。谢谢 -
更改所选索引是正确的方法;
标签: ios swift uitabbarcontroller