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

标签 ios swift uitabbarcontroller

有一个带有多个 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/

相关文章:

swift - String.init(contentsOfFile :) replacement for Linux?

iphone - 在保持触摸的同时按下时隐藏 UITabBar

ios - 将变量传递到 Firestore 文档路径

ios - 在平移手势或拖动上更改 View Alpha

iOS - 背景 View 正在消耗触摸事件

ios - 切换标签栏包括发送数据

objective-c - NSNotification 或 Delegate 以在可见 View 更改时进行注册

iphone - View 加载期间 iOS 6 中的设备方向处理?

iphone - 如何解析Json对象

swift - Firebase Realtime DB - 从数组获取特定数据?