gpt4 book ai didi

ios - 错误应用程序尝试以模态方式呈现事件 Controller Swift

转载 作者:行者123 更新时间:2023-11-30 11:40:55 26 4
gpt4 key购买 nike

有一个带有多个 UIViewController 的 UITabBarController。在其中一个 Controller 内,当满足特定条件时,我想实例化另一个 UIViewController,它是同一个 UITabBarController 的子级。我不断收到此错误“应用程序尝试以模态方式呈现事件 Controller ”,但我不明白 ScheduleNavController 如何已处于事件状态。我在SO上查找了几个答案,但我仍然不明白我的错误是什么以及如何解决它?应用程序的流程如下:WelcomeViewController、LoginViewController、UITabBarController 以及 UITabBarController 的子级。

   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
})

}

enter image description here

最佳答案

感谢 Andreas Oetjen 建议使用 UITabBarController 的 selectedIndex,我想出了另一个解决方案。但是,我仍然不知道应该如何修复原始问题中的代码以使其正常工作。

 //select index of the UIViewController we want to switch to 
// get the UINavigationController for the tab we want to switch to
// get UIViewController to which we want to pass data
self.tabBarController?.selectedIndex = 1
let scheduleNavController = tabBarController?.viewControllers?[1] as! UINavigationController
let scheduleVC = scheduleNavController.childViewControllers[0] as! Schedule
scheduleVC.segmentedControlIndexReceivedFromClaimDetail = self.segmentedControlIndex

//remove the the current UIViewController from which we switch to another controller above.
let claimDetailNav = tabBarController?.viewControllers?[0] as! UINavigationController
let claimDetailVC = claimDetailNav.childViewControllers[1] as! ClaimDetail
claimDetailVC.removeFromParentViewController()

关于ios - 错误应用程序尝试以模态方式呈现事件 Controller Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49298209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com