首页 > 解决方案 > 呈现 EKEventViewController

问题描述

我试图理解为什么我不能直接呈现 EKEventViewController() 而不将其转换为 UINavigationController。

如果我执行下面的代码,我会遇到错误“ Application tried to present modally a view controller <EKEventViewController: 0x11ecfd000> that has a parent view controller <UINavigationController: 0x11f39ea00>.”:

let eventViewController = EKEventViewController()
eventViewController.delegate = self
eventViewController.event = event
eventViewController.allowsCalendarPreview = true
eventViewController.allowsEditing = true
if let topVC = UIApplication.shared.topMostViewController() {
   topVC.present(eventViewController, animated: true, completion: nil)
}

但是,如果我将它添加到 UINavigationController,那么它会很好。

if let topVC = UIApplication.shared.topMostViewController() {
   let navBar = UINavigationController(rootViewController: eventViewController)
   topVC.present(navBar, animated: true, completion: nil)
}

只是想了解为什么“topVC.present(eventViewController,animated:true,completion:nil)”不起作用?

标签: iosswiftekeventekeventkitekeventviewcontroller

解决方案


推荐阅读